An iPhone with the sim locked?

If I buy an iPhone that came with a locked SIM card will I just be able to insert my SIM card & things work fine?

When it means locked it means it is locked to that carrier. So if it is locked to T-Mobile then any T-Mobile SIM card will work, but any other carriers won't work unless you pay to get it unlocked.

Only if the new SIM card belongs to the same network as the old.

Not supposed to sell the phone with the SIM & its the phone that is locked not the SIM. If the phone is locked then it would only work if it is unlocked or if it is locked to the same carrier SIM you have now.