First, generally when you do this you will get a circle with a slash through it (prohibitory symbol) telling you the OS is bootable, but incompatible with the hardware.
Second, these Apple blade style SSDs cannot always be swapped between different models (some can & some cannot...there is no easy way to tell). Sometimes macOS may refuse to boot even to external media such as Internet Recovery Mode, or it may boot with some other odd behavior. macOS is too smart for itself sometimes because those SSDs will work just fine in other hardware when used with a non-Apple OS such as Linux. Even if macOS will boot with the incorrect blade style SSD, the Apple Diagnostics may report an SSD failure....again because the diagnostics know it is not the correct SSD for that model computer.
Assuming you can boot into Internet Recovery Mode using Command + Option + R, then you can perform a clean install of macOS by first erasing the whole physical SSD before selecting the "Install macOS" option. Within Disk Utility you may need to click "View" and select "Show All Devices" before the physical SSD appears on the left pane of Disk Utility. Erase the whole physical SSD as GUID partition and APFS (top option)....make sure to give the volume a good name.....from the factory it is named "Macintosh HD".
If you can still boot one of these laptops normally, then I highly recommend you create a bootable macOS USB installer while you still can so you have more options in case you have issues with Internet Recovery Mode working correctly.
Create a bootable installer - Apple Support