The length of time that "dug-in" status lasts is dependent on the unit's encounter settings. IIRC, Murderous and Aggressive cause a unit to immediately leave dug-in status. Normal lasts for two rounds, and defensive for four. This also applies to units behind formal fortifications, with some modifications, though.