To be honest, I have experienced something so similar that my phone failed to detect my SD card one day. This problem, in my experience, is caused by phone file system recognition failure or minor SD card errors. To deal with this problem, you can either update the SD card driver or run CHKDSK to repair minor errors on your SD card.
Provided that you have tested your SD card on other devices, I offer you different ways to troubleshoot your problem.
Fix 1: Update the driver of your phone
Updating drivers is a good solution when your devices (including phones, SD cards, network adapters, monitors, printers, video cards, external hard drives, etc.) are not working.
Step 1: Connect your phone to your PC.
Step 2: Go to Control Panel > System > Device Manager.
Step 3: Locate and expand Portable Devices or Other Devices, depending on which one you see.
Step 4: Right-click the name of the device you connected, and then select Update Driver Software.
With these operations being conducted, insert your SD card into your phone to test if it can be detected.
Fix 2: Run CHKDSK to repair your SD card
You can also run CHKDSK to repair the hard drives on your PC. Read on to repair your SD card errors by running CHKDSK here:
Step 1: Go to the start menu, and type in cmd in the search bar.
Step 2: Right-click cmd. exe and choose Run as administrator.
Step 3: Run the following command in the Command Prompt.
chkdsk *: /f /r /x
You need to replace * with the drive letter you wish to repair. For example, if you want to repair the G drive, you need to type in chkdsk G: /f /r /x.
Hope this answer deal with your problem!