My 3ds turnes off randomly with a pop

If I turn it on is just closes with a pop randomly

This is most likely due to a ribbon cable in the hinge that is bad and/or going out. It is the cable that connects your top screen. It might seem random because when you get your 3DS or its hinge at just the right angle the 3DS recognizes that there is an issue or loses connectivity from that cable and it forces itself to shut down immediately.

Pretty sure you can buy a replacement ribbon cable and once you swap it, it should solve that issue