Special CBI court judge J K Pandya allowed Pandey's discharge application on the ground that there was no evidence against him related to the kidnapping and murder of Ishrat Jahan and three others.
The CBI, which investigated the case, had accused Pandey, who then headed the Ahmedabad crime branch, as being involved in the alleged fake encounter.
The court on Wednesday said that no witnesses accused Pandey of the murder and kidnapping of the victims.
It also said that the witnesses' evidence was contradictory as they gave different pieces of evidence to different investigating agencies.
The court also held that being a government servant, permission to prosecute Pandey was not taken by the investigating officer from the state before the filing of the charge sheet against him, as per section 197 of the CrPC.
In the first charge sheet filed by the CBI in 2013, seven Gujarat police officers were named as accused, including IPS officers P P Pandey, D G Vanzara and G L Singhal, facing charges for kidnapping, murder and conspiracy.
The CBI had named four IB officials, including IB's special director Rajinder Kumar and officer M S Sinha, in the supplementary charge sheet, which still awaits the Centre's sanction.
The city crime branch officials had gunned down 19-year-old college girl Ishrat Jahan from Mumbra in Maharashtra, her friend Javed Sheikh alias Pranesh, Zeeshan Johar and Amzad Rana in an alleged encounter on June 15, 2004 on the outskirts of the city.