Re: With the new disk, I can reset the system, reinstalling Windows 10 from a Dell recovery USB drive. The machine successfully reboots during the install process, and usually allows me to install all of the Windows updates to bring Windows 10 up-to-date. Then, if I shut down the machine and try to boot it the next day, it again fails to boot. I suggest you not to use the Dell recovery usb but download the Microsoft Windows media creation tool to prepare a latest Windows 10 installation media USB.  Use that USB to do a clean install of Windows 10 Pro. After install go inside group policy to disable Windows 10 auto update. I suspect your pc is stalling the Windows 10 auto update internal adjustment process.  your Dell recovery USB for this PC has an old version of Win 10 for which your PC tries to install all the updates since then.  The 5040 was released in 2015 and Win 10 version was 1507-1607 then.   Instead of letting it stall during update, clean install the latest 21H2 version of latest Win 10 once for all directly from MS, and disable auto update.  If this works, then use this PC with the current version for a good long while. Windows 10 update from a quite old version is a major overhaul of OS.  Many things could go wrong in the machine and not all can be explained by rational reasoning.  The update is always messy compared to clean install of a single version.  Similar reason why Windows 7 update to windows 10 works in theory but is prone to error in practice than Win 10 install with a clean slate.
I have a Dell Optiplex 5040 small form factor which fails to boot. It has 8GB memory and originally had a 500GB hard drive. The BIOS/firmware is the latest, 1.22.0. It boots to the screen with the Dell logo, then the screen blanks and displays the Dell logo with the rotating circle of dots below the logo. It remains at this screen until I power it off. I've left it at this screen for hours. The machine passes all self tests. I can boot from a Linux USB drive and run Linux. I have replaced the hard drive, booted Linux and run the smartctl utility to successfully run short and long tests of the new drive without error. I can boot from a FreeDOS USB drive and successfully run third-party memory tests (memtest86) which show no errors. With the new disk, I can reset the system, reinstalling Windows 10 from a Dell recovery USB drive. The machine successfully reboots during the install process, and usually allows me to install all of the Windows updates to bring Windows 10 up-to-date. Then, if I shut down the machine and try to boot it the next day, it again fails to boot. By the way, attempting an automatic repair fails, a system restore from restore point (when I've successfully restored Windows and created a restore point) fails, and all of the other methods offered by the Dell software fails to resolve the problem. Before I consign it to the dumpster, does anyone have any suggestion on how I can at least determine the cause of this problem, let alone whether it has a possible resolution? Thanks.  
OptiPlex 5040 sff won't boot Windows 10 - any hope?