Think of Jedi Knight. How often do you see stormtroopers alone?
3P0 might have seen a stormtrooper & an imperial officer.
Also, remember that the Vader and his men were there at Lando's sufferance (or so Lando thought). What Threep may have walked in on was a confrontation between stormtroopers and the ubiquitous Wing Guards.
The Guards see stormies as big-time "suits" lording it over the locals (like on TV, when FBI agents butt into a local sheriff's jurisdiction thinking they own the place).
The stormy, possibly to provoke the guardsman into doing something rash, raised his blaster and shot the droid.
A subtle reminder: "I have the power here. One word from me and Lord Vader will crush you and your precious jurisdiction into rubble. You can do nothing against me."
You'll note that, when things went to Hell, the Wing Guards all seemed to be standing well away from the white-armoured fire-magnets.
"The Beasts know much that we do not." -Ancient Jedi proverb