If the company has decided that computers need to be locked when away from keyboard there will be a policy and procedure for reporting and dealing infractions. This won’t be it. While in this case the program might have been mostly harmless, one never knows when a programming error might spin things out of control. It’s clever, funny to some, but if it accidentally resulted in downtime the stuff the flows downhill would come fast and be unpleasant in some organizations. Plus, annoying your teammates isn’t the best idea long term. I know this may seem harsh, but from my experience organizations with the most need for this security would be the least likely to approve of this method.
I think people are too focused on working for military and paranoïa, we need a range of behaviors, from the paranoid to the welcoming, that guy watching your screen could start an interesting discussion about your project, and give you the contact to the right person to help you. You don't want that in a military context, you highly desire it when you're building a vegan pet food marketplace for hipsters.
Not everyone needs to develop like in Aerospace, not everyone needs to develop like in video games, not everyone needs de behave like a NSA agent, and not everyone needs to behave like a farmer's market salesman, we need a range of behaviors.
And whatever the policy, you never, ever, let co-workers be dicks to each others, no "pranks", no public shaming, no sending a prank email from each other's computer. If security is really an big issue, then not locking a computer is a strike, it goes between the boss, the offender and HR, not a matter of joke.