If the used iMac wasn't prepared according to this Apple document, What to do before you sell, give away, or trade in your Mac - Apple Support, you should return it and get your money back. Without the users ID and password you can't erase and restore the Mac so you can set it up as a new Mac.
If you can't send it back but have the receipt you may be able to take it into the nearest Apple Genius Bar or Apple Authorized Service Provider and have them restore it. But you'll need good documentation that you legitimately purchased the unit.