I was wondering how and why to use the lens hood of the Canon EF-S 24mm f/2.8 STM 'Pancake' model (ES-52, which is very small) and a UV filter. Should I use the filter after or before the lens hood?
TL;DR - Go lens -> filter -> Hood, except if the hood causes massive vignetting or corner loss. Don't use a UV for protection - use it to enhance the shot or not at all.
Filters add additional pieces of glass to the lens. The addition of that glass can be associated with additional/worse ghosting or reflections in the right light and a loss of image quality.
So, the question becomes: is the use of the filter and its effect worth the downsides?
If you are attempting to photograph a scene with a lot of atmospheric haze, then a UV filter will help you out quite a bit.
If your scene does not have haze or you are thinking of using the UV filter for "protection" then, in my opinion, you are using the filter and all of its downsides with no upside gained for your shot.
Start Tangent on the idea of UV as protection
On the idea of using a UV filter for protection, everyone has an opinion but consider this: Filters are arguably much weaker than the front element in your lens and, in a drop, will almost certainly break. Though weaker than the front element, they can still scratch that front element during the break. The idea that "it absorbs some of the force" is, to me, a junk idea. If you drop your lens or camera+lens, the force lost to the UV filter is tiny in relation to what's happening to the rest of the gear.
The most common accident that I've seen is: while carrying the camera on a shoulder strap, you move and smack it into an object like a table or wall. If your lens had a bulbous front element, then I'd be worried about hitting it. But it doesn't. In fact, it is somewhat recessed. This protects it.
Take the recessed element idea one step further and add the Lens Hood. This makes it even harder for an object to smack into the front of the lens and is, IMO, the best way to protect a lens in use. The only exception to this is if you are using the lens in a blowing sand environment (beach, dust storm, etc). In that case, yes, use the UV filter to help guard against dirt mucking up the front element.
The purpose of your lens hood is to stop stray light coming in from the sides from causing ghosting or reflections in your shot. Because there is no element to a lens hood, it does not rob you of any image quality. So, about using a UV filter + Hood...
The only reason you'd use both is to photograph a hazy scene and guard against that unwanted light. Normally, You will need to attach the filter to the front of the lens and the hood to a bayonet mount that would attach over top of the filter to the lens such that the filter is contained in the hood.
With the EF-S 24mm Pancake, the hood screws on. Keep in mind the purpose of the hood: to reduce stray light from getting in. This is best accomplished with the hood furthest out on the stack, so the UV would mount first and then the hood on top.
However, this will put the hood a bit further away from the lens than it was designed and you may get vignetting - test to make sure that you are not. (At the extreme, if you were to stack enough filters you'd also get vignetting until finally you start blocking the corners of the shot completely)
If you find that the filter causes vignetting and only want to use the UV filter for a shot, and your framing is suffering from ghosting or reflections...keep in mind that all you need to do to get rid of ghosting is cast a shadow on the lens...use your free hand, a piece of paper, anything really, to block stray light coming in from the sides.