The writers had advisors who had worked within the government and many of the stories were based on real situations. For example, in Yes Minister: The Moral Dimension (1982) they go to an arab state where alcohol is not allowed and so they set up a "communications room" in the embassy where they keep a stash of booze so they could slip out and have a drink. This really happened.
A great fan of the series, Prime Minister Margaret Thatcher (as she then was) wrote a sketch for the show with press secretary Bernard Ingham which was recorded and aired as part of the 1984 National Viewers and Listeners Awards. The sketch featured Paul Eddington and Nigel Hawthorne, both of whom are talking to the Prime Minister (played by Thatcher herself) about her notion to abolish economists.
Paul Eddington, Nigel Hawthorne and Derek Fowlds all hated having to record the show in front of a studio audience (as was the convention for television sitcoms at the time) due to the distraction and often having to pause for audience laughter to die down.