Under what legal standing can after-hours ground access to an airplane be forbidden? (USA-specific only)
As per my answer here the FAA does define &quot;Public Airport&quot; but does not specify that ground access must always be available. The answer mentioned in the question, you link here covers the general scenarios where issues could crop up:

Private Airports: Are generally free to make rules as they see fit and could potentially prevent you from entering the property even if the tie down they offer is free. There are lots private airports in the US and there are even some big airports that are privately owned. Private airports while conforming to certain federal aviation regulations may ultimately be built on private land which falls under different (often local) regulations.
Ports Of Entry: An airport that has customs facilities may prevent you from accessing your aircraft prior to clearing customs or if they have another reason not to let you onto the ramp. This can get tricky as its often administered by the TSA.
Local Regulations: Airports are often owned by local governments or port authorities there is nothing preventing them (as far as i know) from making a rule/regulation that prevented field access at certain times.

The most frustrating issue in my experience is the &quot;Private FBO&quot; problem. Often times airports are publicly owned but physical ramp access is handled by Private FBO's that may chose to not be open 24/7 or may (what sounds like in your case) station a clueless guard at the gate after hours. This creates more of a practical issue than a regulatory one, either the owning authority needs to mandate the FBO allow people onto the ramp at all hours or the FBO needs to step up their game a bit when it comes to educating their employees.
I'd say 8/10 times the gate code is the CTAF frequency...