Welcome to iMore! If it asked for a passcode, then one had previously been set up. If it asks to set one up, then do so.
If it only asked for the code and you don't know it, the only option is to restore the phone via iTunes. You will need to connect to iTunes via computer and put it in DFU mode. You will lose all your data, including photos and will still need your Apple ID and password to set up. If you don't have that, you're out of luck.