I have been following a tutorial, shadow mapping works more or less as expected except sometimes the shadow projects completely weirdly on nearby walls. This isn't sampling outside the lightmap because I use CLAMP_TO_EDGE and if(min(ShadowCoord.x, ShadowCoord.y) > 0.0 && max(ShadowCoord.x, ShadowCoord.y) < 1.0) in the fragment shader. Does anyone know what the official term for this problem is so I can go research it some more? Thanks.
It's not entirely clear what the scene in your picture is supposed to look like, so I'm not sure I'm interpreting it correctly. But if I am, it seems like the problem is that you're projecting the shadow properly, but onto the wrong face of the gray wall. If you want to research it, you might have luck looking up winding order (sometimes called winding number), or back-face culling.
If I'm correct in what's shown above, I think you could solve it in your shader by only applying the shadows to the current fragment if the vector from the light source to the surface points away from the surface normal. In other words, take the dot product of those 2 vectors, and if it's negative apply shadows, otherwise, don't.