I assume you are talking about your Apple ID passsword (which you use for your iCloud account) as oppposed to the passcode for your actual device.
You cannot retrieve it, but you can reset it and create a new password: please see If you forgot your Apple ID password - Apple Support
Once done you will of course have to sign out and re-sign in on any other devices or services using your ID.
If in fact you have got yourself locked out of your phone and don't know the passcode please see LotusPilot's post here: how do I enable my son's Ipad mini, messa… - Apple Community