I am travelling from Bejing to Karachi, transiting through Hong Kong, flying on Cathay Pacific Airways. I am a Pakistani National holding a Chinese visa. I have gap between the flights about 3 hours mean I will stay Hong Kong airport for 3 hours. Do I need any kind of transit visa? And if yes then how I need to apply?
As a Pakistani national, unfortunately, you need a valid Visa for Hong Kong even if you are only transiting and never leave the airside in Hong Kong airport.
You will most likely get one however since it says on this page that:
An application for an entry visa/permit to enter Hong Kong for a visit (leisure, social or business) or transit may be favourably considered if [...] the application is for a transit visa/permit, he/she holds an onward ticket to the place of his/her destination unless the destination is the Mainland of China or the Macao SAR.