Gilani may have been put in jail by Zia but he also served under Zia in the Junejo cabinet of 1985. It was only after Junejo kicked him out of the cabinet that he decided to leave PML. He then switched his loyalties and joined PPP after meeting BB in person in Karachi. So one could say he like many others is an opportunistic politician.
Read more here
BBC NEWS | World | South Asia | Profile: Yousuf Raza Gilani