Would it be legal to unlock an iPhone 4S I purchased on eBay locked?

I do not plan to use it as a phone per se. I only plan to use it for web surfing at home using the wi-fi router on my PC and use the camera for taking local and travel photos.

Doesn't unlocking it require that a phone company do it?

In the US, yes it's legal. However the phone must not have a blacklisted IMEI.

Also, depending on which carrier the phone came from, they may require the last account holder's PIN to go through the unlock process. If you don't have it or can't get access to it, then you can't unlock it.