Various regulatory authorities around the world have framed strict rules prohibiting entry of passengers into cockpit. It makes some sense to not allow anyone into the cockpit (learning from 9/11), while you are flying but when on ground, what is the harm in allowing someone to enter the cockpit? The passengers are frisked thoroughly before being allowed to board the aircraft, and if you are on the ground then there is a lot of security around. So, what are the factors behind not allowing outsiders into cockpit, while on ground?
I don't agree with the strict enforcement of this rule by the DGCA (but I'm not an airline pilot so I think my opinion doesn't really count on this matter). But there is logic behind the ban - many safety-critical actions are completed before the plane has left the gate. Such actions include calculating takeoff speeds, briefing the departure procedures, and completing various checklists.
Having people in the cockpit could prove to be a big distraction when trying to complete these tasks, particularly when the time is limited anyway such as on a short turnaround.
Making a mistake before leaving the gate can definitely end in disaster. Take Emirates flight 407 in 2009. The crew entered an incorrect takeoff weight into the system. As a result there wasn't enough thrust to rotate and the A340 barely cleared the airport fence.