How do iPhones get carrier locked remotely? My original iPhone 5 came directly from Virgin Mobile. As such, it's carrier locked.

A few months back, I had what seemed like a hardware issue, and in the process of troubleshooting it, Apple replaced my handset. They brought me a brand new iPhone 5 out of the storage area in the back of the retail store. 

Apple does not have a Virgin Mobile "version" of the iPhone. Your options are AT&amp;T, Verizon, T-Mobile, Sprint, or no carrier. This means that Apple could not have replaced my iPhone with one that was already locked to Virgin. Additionally, Virgin Mobile has never touched my phone. It went from the Apple Store directly to my pocket.

This indicates to me that the process of carrier locking takes place when you place a Virgin SIM card in the phone and call the company to activate it. Is this correct? Or if I had taken the brand new iPhone from the store and tried to set it up on some other service, would I have found it locked somehow? Does it have to do with restoring my settings from backup?

How does this remote carrier lock work?
Per Virgin Mobile's Unlocking FAQ (emphasis mine):

What does it mean for my device to be &quot;locked&quot;?
The term &quot;locked&quot; means that either Virgin Mobile software or the manufacturers' device designs restrict the device to use with a carrier operating on Sprint's network, such as Virgin Mobile.

They gave you a Sprint model at the Apple store.