I've dealt with plenty of animals over the years, and hamsters are basically furry Houdinis. You've got a 40-gallon which is solid, but the issue is those little guys can compress themselves down to pretty much nothing. If there's a gap, they will find it and they will use it. I've seen it happen with my own eyes - a Syrian will squeeze through something you'd swear is physically impossible.
Do yourself a favor and get a flashlight and inspect that tank like you're doing a pre-trip inspection on a rig. Check every single seam, every connection point where panels meet, around any water bottle or feeder you've got in there, under the lid, everywhere. Sometimes it's not even an obvious gap - could be something warped slightly or a piece of bedding creating just enough space. Run your fingers along all the edges too. Once you find the weak spot, seal it up proper. Some people use duct tape, some use clips or clamps depending on what you're dealing with. I'd also make sure the lid actually fits snug and isn't sitting loose.
The other thing to consider is whether he's actually escaping regularly or just testing things out. Hamsters will probe for weakness even if they're not starving to get out. But if he's consistently getting loose, that's a problem you gotta solve because they can get into trouble fast out of the tank - walls, wiring, you name it. Take the time now to do a full lockdown of that enclosure and you won't have this headache in 2026 or any year.