[Xiaomi Mi A2 Lite Questions & Answers] a1291762:
Ok, so here's my notes I was making as I looked at the logcat...

You can get logcat by enabling developer mode (not root).

Matlog can work without root (I have root, but deny Matlog root permissions when it asks).

adb logcat from a computer works without root.

These are Linux/MacOS commands. Windows is a little different (no grep). Advanced text editors generally have "find" functionality so you can filter out lines from a file.

First, lets save your logcat to a file. This runs forever (captures the current log and then writes new logs as they happen). After a few seconds, just press Ctrl+C to stop it.

adb logcat > logcat.txt

This shows various storage events (MOUNTED, EJECTING, UNMOUNTED, REMOVED, CHECKING). The one that signals a hardware issue is BAD_REMOVAL (I only get this if I eject the tray without unmounting first).

grep StorageNotification: logcat.txt
07-21 09:51:02.510 2199 2199 D StorageNotification: Notifying about public volume: VolumeInfo{public:179,65}:
07-21 09:51:02.510 2199 2199 D StorageNotification: type=PUBLIC diskId=disk:179,64 partGuid= mountFlags=VISIBLE mountUserId=0
07-21 09:51:02.510 2199 2199 D StorageNotification: state=BAD_REMOVAL
07-21 09:51:02.510 2199 2199 D StorageNotification: fsType=vfat fsUuid=48C7-13E5 fsLabel=4GB
07-21 09:51:02.510 2199 2199 D StorageNotification: path=/storage/48C7-13E5 internalPath=/mnt/media_rw/48C7-13E5

This shows when Google Photos was started up due to a change in storage. These should line up with StorageNotification events.

grep ExternalStorageStateChangeBroadcastReceiver logcat.txt
07-21 09:42:50.209 2032 2048 I ActivityManager: Start proc 19428:com.google.android.apps.photos/u0a133 for broadcast com.google.android.apps.photos/.sdcard.envcache.ExternalStorageStateChangeBroadcastReceiver

I use a Magisk module (debloater) to "remove" Google Photos and then installed it from the store (so that it's a USER app, not a SYSTEM app). This allows me to do things like turning on battery restriction (ie. don't run in the background), which is probably why I see things like this:

grep -i photos logcat.txt
07-21 10:01:50.392 2032 4479 W ActivityManager: No permission grants found for com.google.android.apps.photos
07-21 10:01:58.104 2032 11555 W ActivityManager: Background start not allowed: service Intent { cmp=com.google.android.apps.photos/com.google.android.libraries.social.mediamonitor.BackgroundThreadNotifierIntentService (has extras) } to com.google.android.apps.photos/com.google.android.libraries.social.mediamonitor.BackgroundThreadNotifierIntentService from pid=20276 uid=10133 pkg=com.google.android.apps.photos startFg?=false

It is in theory possible to use adb commands to uninstall Google Photos and then install from the store to get the same effect without root...

I was doing some general searching and it seems that hardware issues commonly cause this. Things like bent pins, loose sockets, etc. You describe the SD card as unmounting when the phone is off, but is it perhaps that the SD card unmounts when the phone is moved around (which happens to be when it is off)?

In any event, the logcat should be able to show if the OS thinks the card is being removed.