The reason psql in general works with both older and newer PostgreSQL versions is because libpq does (psql is implemented using libpq). In general the PostgreSQL client-server wire protocol that libpq talks does not change between PostgreSQL versions, it's remained compatible since PostgreSQL 7.4. It's fairly routine that you would have a client version different from the server version in more complex environments, and not a problem.
Now, it's possible you are sending a query for one PostgreSQL version (the client version) that doesn't work on an older or newer version of PostgreSQL (the server version) using libpq. The server may return an error for such queries, just as it would return an error for any query it determines is invalid. It's the client's responsibility to send the appropriate queries for the server version in use.
Thanks,
Jeremy