Make sure to erase the whole physical drive as GUID partition and either APFS for macOS 10.14+ or MacOS Extended (Journaled) for anything earlier. You may need to click on "View" within Disk Utility and select "Show All Devices" before the physical drive appears in the left pane of Disk Utility. Quit Disk Utility and select "Reinstall macOS".
If this doesn't work, then please provide the exact model of the computer by entering your serial number here or here. Also provide the version of macOS you are installing. What was the version of macOS on the old drive? What is the make & model of the SSD?
The hard drive cable in the MBPro 13" (mid 2012) model has an extremely high rate of failure. If you have this model, then you should replace the cable.