You are confused.
"No, I was not the one who chained you down here," you say.
The dragon stares at you.
"I can only be free if someone speaks the name of the person who chained me to this place," they say. "Do you happen to know who lives here? If you do, they are the one who imprisoned me, and their name is the key to getting out of this place!"
The dragon waits for you to find the name and unlock the front door - with the codes broken the dragon will also be free!