How can you film someone being directly stabbed through any part of the body (especially the head, as seen in Game of Thrones) when the camera has not shifted angle at all?
It's done on computers.
Sometimes they also use a prop knife, the kind where the blade pops back in when touched.
Some Game of Thrones VFX examples here
Of course, older movies didn't have the luxury, so they had to make due with... tricky camera angles, multiple shots, cuts and edits. And practical effects where they build up the shot with multiple prosthetics, in a stop motion type of way.
An old impalement illusion used by stage magicians involves wrapping a corset or frame around the body part (such as the neck or torso) which is to be "impaled". The corset contains entry and exit slots on opposite sides of the body part, and an interior pocket or track wrapping around the body through which the sword blade moves.
The sword itself is a flexible prop which is inserted into the slot in the corset, sliding around the victim's body in the pocket as the sword is pushed, until it emerges from the exit slot. The effect is quite convincing, especially when blood and gore effects are added in.
However I couldn't find explicit references to this trick being used in movies. Maybe old Kung Fu or ninja films from the 1970s or 80s?
They used this technique in the movie "Your Highness". This is a link to the gag reel and you can see it at about 1:40
Depending on the production values and budget, often you are seeing a mixture of practical effects and digital compositing with computer graphics. The technique is also determined by the requirements of the shot and how the action plays within the scene and story. For example, a quick "in out" might be easier to do with cgi. An articulated sawing or turning of a blade might require the combination of more advanced techniques.
Practical visual effects are not always so easy to unravel. Like magicians guard their secrets, so too do practical visual effects wizards.
In the above video, an example of impalement is deconstructed. It involves not only a fake tip and a doubly retractable impaler on the entry side, but it uses magnetics to achieve the exit wound. It largely relies upon timing, misdirection and a crew of trained performers.
Simple "sword through" magic trick kits are also available to give an idea of how something similar might be achieved:
Note the length of the sword before going in and after coming out. It has bent through the "stock" around the neck. These kinds of kits are widely available. Add a magnetic extension to the blade inside the stockade which gets pushed through when the sword is inserted, and voila - movie magic.
Depending on the staging, simple sometimes works just fine. For example, a sword through the chest could be staged so the actors' sides are facing the camera and one "stabs" the other under the armpit. Done with the right lighting and acting, this could look like it was through the heart and the "stabbed" actor could back away from the "stabber" while the sword is held "through" them. Rig up a sword with a small hand activated pressure pump and squirters in the back and you get appropriate blood spray:
Filming shots which are to be composited digitally involves some planning. Essentially though, the film crew needs to shoot all the necessary practical elements (as contrasted to the computer generated elements such as 3D and 2.5D rendered effects) which will be composited together. Compositing still shots tends to present fewer challenges, but lots can be done with motion blur and other digital effects to make all the elements appear as a seamless image. The compositing involves scanning the elements, working in layers, using alpha channels to put cut outs into a scene, removing green (or blue) screens, and there are lots of 2.5D and 3D techniques depending on the complexity of the visual effect. Once finished the digitally composited shots need to be matched back into the scene. There is a whole world of artistry and science involved.
A shot of someone getting stabbed through the head might involve the main footage of the actor being stabbed and angled to get their facial reaction. We might also see the hand with the sword. Likely the stabbing actor will have a handle and possibly a soft "green" sword end so they can contact the stabbed actor without hurting them. Possibly, the actors might be filmed with high speed cameras or go through the motions slowly. Based on the angle of the sword blade, an element of the "business end" of the sword can be composited as coming out the back. The actor might have a "blood pack" in their mouth, or squibs in the back of their head, or blood may be added digitally. If the hilt or base of the sword and the pointy end are both in the shot, it's just a matter of working out the illusion adequately so that the sword appears to be whole (using the angle of the entry, judging the depth based on the camera angle and lens width, etc.)