A 2012 iMac will not be able to install the newest macOS or any macOS beyond Catalina, with or without a new hard drive.
Also see the following from Identify your iMac model - Apple Support
iMac (27-inch, Late 2012)
Model Identifier: iMac13,2
Part Number: MD095xx/A, MD096xx/A
Newest compatible operating system: macOS Catalina
Tech Specs: iMac (27-inch, Late 2012)
User Guide: iMac (27-inch, Late 2012)
iMac (21.5-inch, Late 2012)
Model Identifier: iMac13,1
Part Number: MD093xx/A, MD094xx/A
Newest compatible operating system: macOS Catalina
Tech Specs: iMac (21.5-inch, Late 2012)
User Guide: iMac (21.5-inch, Late 2012)