In cases where the output has low entropy - eg, you've asked a model to repeat some input text verbatim, or to answer a question that has exactly one correct answer - there will be no randomness for the watermark to hide in, so the output will effectively not be watermarked. Code lives somewhere in the middle: it generally has less entropy-per-token than prose, so would need more tokens to reach a given level of detectability.
There are lots of ways to restrict output samples. The simplest conceptually would be to just use a restricted pool of PRNG seeds, but in practice there are more sophisticated constructions to try to build in robustness to minor edits, allow detectability without needing the original weights and prompt, etc. Google's SynthID paper (https://www.nature.com/articles/s41586-024-08025-4) is a good starting point if you want to understand a recent production-ready method (or you can just ask an LLM to explain it to you).
Toy proof-of-concept: Anthropic owns a secret key which is a coin-flip Bernoulli random variable K with p=1/2. You are paying Anthropic to give you X, a Bernoulli random variable with p=1/2. Anthropic changes from their old strategy, "draw from K, then throw it away and flip a coin, each time you ask for a sample", to their new strategy, "draw from K and send it to you". You cannot observe the difference, but Anthropic knows K and so they know when you are repeating its outputs. (Obviously this is a toy example; in reality the distribution is vastly more complicated than Bernoulli, and Anthropic isn't just storing some model outputs to use as K but instead is computing a correlation with a known pseudorandomness source.)
Before: "He leaped at the chance" - 33%. "Jumped at the opportunity" - 66%.
After: "He leaped at the chance" - 33%. "Jumped at the opportunity" - 66%.
But if you refresh your response from Anthropic 100 times:
Before: "Jumped at the opportunity" He leaped at the chance" "Jumped at the opportunity"
After: "He leaped at the chance" "He leaped at the chance" "He leaped at the chance"
The second one is detectable as being watermarked.
davmre has a good explanation that's more in-depth.