As @KatieR states in the answer to Why did Snape tell Voldemort when Harry Potter was really going to be moved?, Dumbledore told Snape via his portrait in the Headmaster's study. But how did Snape get in there. Later in the book, when he takes the sword to the Forest of Dean, Snape has been made headmaster by Voldemort according to Dumbledore's plan and they can easily talk, but since Harry was moved before the Ministry takeover, how did Snape - the wanted killer of the previous beloved headmaster - manage to enter his victims office for a little chat??
I actually do believe this is a straight up plothole that JKR missed. So the only way to get around it is with questionable and unprovable assumptions.
And interestingly, the question actually misses parts of problem.
Not only is Snape not headmaster yet, the acting headmistress is actually McGonagall. Only she should have access to the office at this time and at this time she seems to fully believe in Snape's treachery.
It was several minutes before Harry became aware that they were not heading for Professor McGonagall's office, but for Dumbledore's, and another few seconds before he realized that of course, she had been deputy headmistress,… Apparently she was now headmistress … so the room behind the gargoyle was now hers.
-The Half Blood Prince, Chapter 29: The Phoenix Lament
We are also informed earlier, in Order of the Phoenix, that the portraits are "honour-bound to give service to the present Headmaster of Hogwarts." So, Dumbledore's portrait shouldn't even have been able to serve Snape at this time. (although "honor-bound" may not mean "magically bound," and as Nigellus Black showed, they can show at least a certain amount of insubordination if they wish.)
So, It's not just how he got access, it's how he received permission. If we are forced to come up with an explanation I think the only one that makes sense is that Dumbledore prearranged for Snape to have access to the room and somehow made sure that McGonagall would not interfere. She would have surely obeyed postmortem wishes of Dumbledore so, if provided with such instructions, she could give some sort of blanket magical allowance to her room to, and pass on instructions to the portraits to cooperate with, "those who are loyal to Dumbledore."
This is a great question and the only solution I can come up with is this.
Snape was appointed Headmaster before the information became public knowledge.
We know that following Dumbledore's death that Voldemort's influence in the Ministry and in wizarding society in general was on the rise. Even before Scrimgeour was removed, Voldemort had considerable influence over many of the key decision-makers in the Ministry.
"...as Head of the Department of Magical Law Enforcement, Thicknesse has regular contact not only with the Minister himself, but also with the Heads of all the other Ministry departments. It will, I think, be easy, now that have such a high-ranking official under our control, to subjugate the others, and then they can all work together to bring Scrimgeour down."
(Deathly Hallows, Chapter 1, The Dark Lord Ascending).
Of course, it's not made clear here who has the final say over the choice of Headmaster but the fact that McGonagall and the other teachers wouldn't have accepted Snape's Headship unless they were forced to do so suggests that it's a Ministry decision. Given the centrality of Hogwarts in the wizarding world, securing it for Voldemort would I'm sure have been a priority for the Death Eaters - even if their wider goal was taking over the Ministry as a whole.
News of Snape's appointment only become public on September 1st.
On the first day of September there were more people lurking in the square than ever before.
(Deathly Hallows, Chapter 12, Magic is Might).
For logistical reasons the appointment of the new Headmaster (and Muggle Studies/DADA teachers) would need to take place well before the start of term. Only then was the information made public with the appropriate amount of ensuing Daily Prophet propaganda. If we didn't have this conversation between Snape and Dumbledore's portrait then I'd have said Snape's appointment would've been made after the Ministry fell. However, based on the information in The Prince's Tale, Snape must have been appointed sometime between Dumbledore's funeral and Harry's 17th birthday to allow him to have that conversation. Therefore, Snape had the freedom of the Headmaster's office and could commune with Dumbledore at will. And, really, it's lucky that Snape was innocent because otherwise having that portrait around would've been seriously awkward.
As we know from the end of DH, Dumbledore had completely planned his death from the moment he was infected by the curse from the ring. Therefore, he had ample time to inform Snape of the plan, and as we've seen, Snape is the only person Dumbledore told most of his plans to. Hence, we can see that Snape needn't have visited Dumbledore's office to talk with him, and complete his plan, because he would've already known what to do, removing all need to visit Dumbledore's office, and simply planting the ideas in Mundungus' head for the change in time for Harry's removal, and tipping off Voldy. No contact with Dumbledore needed, until Snape returns as headmaster
This is admittedly conjecture (albeit based on references), but here's my theory:
Dumbledore appointed Snape as headmaster before he died. Note that this is different from The Dark Lord's answer which also argued that Snape had already been appointed headmaster, in that according to his answer Snape was already appointed by Voldemort's side. As I mentioned in a comment there, that does not seem to be correct because the Daily Prophet article announcing Snape's appointment on the first day of school says (my emphasis):
"'Severus Snape, long-standing Potions master at Hogwarts School of Witchcraft and Wizardry, was today appointed headmaster in the most important of several staffing changes at the ancient school.
My argument that Dumbledore had previously appointed Snape as headmaster is based on the following passage at the end of Deathly Hallows (from Snape's memories):
"Lord Voldemort foresees a moment in the near future when he will not need a spy at Hogwarts?"
"He believes the school will soon be in his grasp, yes."
"And if it does fall into his grasp," said Dumbledore, almost, it seemed as an aside, "I have your word that you will do all in your power to protect the students of Hogwarts?"
Snape gave a stiff nod.
It doesn't seem reasonable for Snape to be able to protect the students if he is not at Hogwarts. It seems very possible that Dumbledore intended Snape to be headmaster in order for him to be able to protect the students (as well as do other things for Dumbledore).
We know a little bit about headmaster appointing from Order of the Phoenix.
The Fat Friar told me …” He dropped his voice conspiratorially, so that Harry, Ron, and Hermione had to lean closer to him to hear, “… that Umbridge tried to get back into his office last night after they’d searched the castle and grounds for him. Couldn’t get past the gargoyle. The Head’s office has sealed itself against her.” Ernie smirked. “Apparently she had a right little tantrum...”
“And what brings you here in the early hours of the morning?” said Phineas. “This office is supposed to be barred to all but the rightful headmaster. Or has Dumbledore sent you here?
We see that the office did not consider Umbridge to be the rightful headmaster despite being appointed by the Ministry. It would not be surprising if the office would accept Dumbledore's appointees as the rightful headmaster.
Thus, if Dumbledore had, in fact, appointed Snape as his successor, Snape would have no trouble getting into the office (assuming he could get to Hogwarts in the first place, or perhaps travel directly into the office).
In fact, to take this conjecture a step further, perhaps Voldemort was aware that Dumbledore appointed Snape as his successor (i.e. Voldemort thought that Dumbledore mistakenly thought that Snape was on his side and thus appointed him), and (part of) the reason why Voldemort appointed Snape as headmaster was precisely because he would be the only one of Voldemort's henchman who could access the office since he was actually the "rightful headmaster".
And when the Daily Propher reported that Snape was appointed "today" it would have been referring to his official appointment by those currently in power. That official appointment may have actually happened that very day even though Dumbledore had already appointed him months earlier.
Now one might ask how McGonagall was able to access the office at the end of Half-Blood Prince if Snape was really the right full headmaster. To that we could suggest that McGonagall was not entering the office as the rightful headmaster (headmistress) but as a regular teacher (though she might not have known it). Even when Dumbledore was alive, other teachers were able to enter his office with the password. As long as McGonagall knew the password she would be able to enter.