Why are zk-SNARKs possible, in layman's terms
When you have eliminated the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)


If I find you in my dorm room and the door and windows are intact, I can only conclude that you somehow learned the entry code, because I do not know of any other way by which you could have entered my room without breaking the door or windows.

A ZK-SNARK for a function $f$ is similar: if you present a proof for the result $1$ which can pass the verification procedure, it necessarily means that you must know an $x$ such that $f(x) = 1$. This is because we do not know of any (efficient) way to generate such a proof if you do not know such a value $x$. In fact, we have a proof that being able to do this would imply being able to solve certain mathematical problems which are believed to be hard (you can think of factoring integers, although the problems used to construct SNARKs are more complicated). So when you say


  Intuitively it seems like there would be plenty of ways for the client to alter the program code in order to produce output which could be used to fake their identity.


... there may or may not be, but we do not know of any and we consider it very unlikely (i.e., impossible, for all practical purposes).