The scene in the books:
"So I give you fair warning, Potter," Snape continued in a sorter and more dangerous voice, "pint-sized celebrity or not - if I catch you breaking into my office one more time -"
"I haven't been anywhere near your office!" said Harry angrily, forgetting his feigned deafness.
"Don't lie to me," Snape hissed, his fathomless black eyes boring into Harry's. "Boomslang skin. Gillyweed. Both come from my private stores, and I know who stole them."
Harry stared back at Snape, determined not to blink or to look guilty. In truth, he hadn't stolen either of these things from Snape. Hermione had taken the boomslang skin back in their second year - they had needed it for the Polyjuice Potion - and while Snape had suspected Harry at the time, he had never been able to prove it. Dobby, of course, had stolen the gillyweed.
"I don't know what you're talking about," Harry lied coldly.
"You were out of bed on the night my office was broken into!" Snape hissed. "I know it. Potter! Now, Mad-Eye Moody might have joined your fan club, but I will not tolerate your behavior! One more nighttime stroll into my office, Potter, and you will pay!"
Ways Snape would know/accuse Harry:
A- Why won't he accuse Harry of anything possible.
B- He suspects Harry was out in the night + In that same night someone broke into his office and stole Polyjuice ingredients= Harry stole it.
C- The scene in book 2:
"If I ever find out who threw this," Snape whispered, "I shall make sure that person is expelled."
Harry arranged his face into what he hoped was a puzzled expression. Snape was looking right at him, and the bell that rang ten minutes later could not have been more welcome.
Snape could have read Harry's mind right there. but since he couldn't prove it was Harry, he just remembered it and he might have been referencing that incident.
D- Did you notice how Snape's eyes were "boring into Harry's", and that "Harry stared back at Snape, determined not to blink"? I can bet Snape was using legilimency right there. That's why right after, Snape didn't accuse Harry of stealing! Instead, Snape accuses Harry of being out the night his office was broken into.
E- Combining all the answers: Snape added 1+1 and thought that when Harry was out in the night, he stole some Polyjuice ingredients. He also knew that Harry had something to do with the stealing in book 2. Therefore Snape accused Harry of stealing. Harry finally looked up into Snape's eyes and Snape used legilimency on him, discovering that Harry didn't actually steal. Snape, however, still needs to accuse Harry of something, so he accuses him of being out in the night the office was broken into. Snape than also for no reason accuses Harry of going into his office, because it's Harry Potter and Snape hates Harry Potter.