If the output size of SHAKE128/256 is variable, why is the security fixed at 128/256? The general idea is that the security strength of a good hash function is equal to half it's output length. The output length of SHAKE128 and SHAKE256 is variable, but their strengths are still said to be 128-bit and 256-bit, respectively. Why is that the case?
The inner functions have been specifically designed to only support 128 bit or 256 bit security: it's half of the capacity of 256 or 512 bits. The underlying functions or structure do not change.

You can see this from the following picture, taken from the Noekeon site about generic sponge constructions (SHA-3 / SHAKE / Keccak is a sponge construction):



the capacity is $c$ on the left hand side.

So the output is generated at the squeezing stage, while the capacity (as input for $f$ stays 256 or 512 bits).

This may not matter as much as you think, 256 bit security is considered enough to protect against analysis with a quantum computer. The security won't decrease even if large output is generated.

More information can be retrieved from the Noekeon site:


  When using a random sponge as a security reference, one considers the success of a particular attack. Such a success probability depends not only on the nature of the attack considered but also on the chosen parameters of the random sponge, i.e., its capacity, bitrate and whether it calls a random permutation or a random transformation. The flat sponge claim is a simplification in the sense that we consider only the worst-case success probability, determined by the upper bound on the random oracle differentiating advantage [Bertoni et al., Eurocrypt'08], which depends solely on the capacity of the random sponge. Hence, it flattens the claimed success probabilities of all attacks using a single parameter: the claimed capacity $c_{claim}$.


Later it is mentioned that $c_{claim} = c$.