Can a tmobil iphone 5 work with a AT&T sim card?

I bought a tmobil iphone 5 from my friend and he factory reset it for me. When I go to set it up it says sim required over and over again. I called my friend since he has a iphone but his sim card is with AT&T can his sim card work on my tmobil iphone 5 so I can get past the set up menu

Yes, as long as the T-Mobile phone has been unlocked, and has been paid for in full.

If he was still making payments on the phone it will be blacklisted until it is paid for in full.

If the phone was lost or stolen, it will be blacklisted.

If the phone's owner skipped out on paying their bill, it will be blacklisted.

If the iPhone is iCloud locked, and your "friend" can't remember his Apple ID, the phone is locked for good, at least until he remembers his Apple ID.

Nope. That T-Mobile iPhone 5 is locked to T-Mobile so any other carrier's SIM will not work unless it is unlocked. A factory reset is not an unlock.