Basically gil was coerced into working with them to save margareth. Margareth had a sort of invisible demon guard he couldnt see or do anything about, that would have killed her (if the ladyknight gave the order) if he didnt join the faction. So he also faked his alliance to them and tried to make it look like he believed in their cause, still ofc they left the demon on margaret for insurance (Also the teletrasporting knigh with the freaking helm who was in charge of gil kinda had a crush on him and was jealous of margaret). The fact she was in prison of her own choice, its a bit a half lies/half truth.. as she wanted to take care of her own father, but they had to control the royal family so they couldnt let em roam freely, plus she was also despised by the knight lady, and it the knight lady who said that marg was free to go whenever to elizabeth (even tho the door was locked untill she opened it at the end). She prob said that to confused elizabeth, and when she let margareth go, the lady prob thought that gil was on her side, plus they didnt need to control the royal family anymore due to the their plan reaching its own conclusion (in thier mind). The monster also had no free will iirc, it was controlled by they lady, and the lady also checked on gil with another pet. So its not like the pet could do anything, think of it as a bomb strapped on you ready to go off if u didnt do as u were told.