I've found a pretty good explanation of how to pull off this glitch in this thread:
Okay so, to start off with, you need to have as close as possible to a perfect room 1 and room 2, you can still get a 380 that's too slow. Example here, first ever time the trick was done on real cart. Check chat replay to see how I handled it
Then, you need to jump off the stairs and while in the air press left then right for a very specific amount of frames. Which will change depending on where you jumped off the block. Then if you happened to get inputs in the air correct, you need to hope you land on a very specific pixel on the block. If you land anywhere else apart from that pixel then the trick won't work.
Then comes actually doing the trick. This part isn't very hard but there's a lot of variance. The basic inputs are, hold left for 4 frames and jump on the 4th, releasing left at the same time. That's not the only way that works though.
Sounds decently simple right? Well not so, as sub-pixels also play into account. Even if you managed to do the set up and your lined up correct, your sub-pixel could be as such where the trick just isn't possible.
I found an attempted explanation by the first person to successfully pull off a flagpole glitch in this thread. The explanation is for the flagpole glitch on 8-2, so it mentions a Bullet Bill, but the rest applies to the flagpole glitch in 1-1.
Normally when completing a level Mario will grab the pole, slide to the bottom, hop off and walk to the castle. Once he reaches the castle the timer countdown begins. There's actually an invisible block just to the right of the door to the castle that Mario ends up walking into. This block prevents Mario from walking past the castle door, and also triggers the game to hide Mario behind the background making it look like he entered the castle. So the game is constantly checking to see when Mario is walking into a block to do 2 things: hide Mario and start the timer countdown. The trick used in speedruns is to jump on the bullet bill at a specific position in order to temporarily clip into the block that the flag pole is sitting on, allowing Mario to grab the pole and then immediately get forced OUT of the block to the left. Thus, Mario is immediately touching a block, tricking the game into hiding Mario behind the background and to start the timer countdown without any delay, skipping the entire animation of the flag coming down and Mario walking to the castle.
I also found a tutorial of how to do this in a TAS and it even includes a video.