Try an SMC reset and a PRAM reset (for older Macs 2017 and earlier hold the PRAM reset for at least three chimes or a full minute so it actives several times).
Try connecting the Mac directly to the router using an Ethernet Cable for a faster and more reliable connection and to avoid any WiFi issues. I'm not sure what the "-5101D" error is as I've never seen it before.
If your Mac can boot, then run EtreCheck and post the report here using the "Additional Text" icon which looks like a piece of paper.
Run Disk Utility First Aid. Even if First Aid shows everything as "Ok" click on the "Details" to see if there are any unfixed errors. If there are unfixed errors, then you will need to backup or clone the drive and erase the original drive before reinstalling or restoring from the backup/clone.