3DS XL Turning Off Randomly and Cartridge Problem

So I recently bought a used 3DS XL off or Ebay and was told that there were no issues. But since messing around with it the system has turned off twice on its own without warning. But when turning it back on it acts normal. I can’t tell if anything is triggering that or if it’s just a random occurrence. Then the other problem i’m having is that a game that was included with the console is having issues. It’s Pokémon Sun. When I load it up it works fine but when closing it it does the normal thing by going to the main menu and asking if you want to close the game. After doing that another screen pops up asking to “Please Wait….” and then both screens shut off but the backlight is still on. That lasts for around 5-10 seconds and then it comes back on and seems to be fine. It’s done that both times that i’ve closed that game. I’ve yet to test it on a different system to see if it’s a problem with the cartridge itself or the console. I’ve put a different cartridge in the 3DS XL and hi it closed normally without doing that. So i’m hoping someone on here has a solution.

My 3ds Xl Crashed 3 times and after the first i had a Bsod so it could be the Storage