It does work with pirated games AFAIK.
Steam as a platform is very open in many ways. Likely not intentional, just holes that never got plugged.
Most of the pirated steam clients just lie and say you're always playing a free Steam game that everyone owns and use that to backchannel all of the steam features like messaging, p2p, etc.
Last I checked they even had some rigged up system for achievements since some games interact with them in ways that are needed.