Simply being public doesn't mean it's in the public domain - this applies to movies, art, code, etc.
One example of restrictive but public licenses include requiring others to share their source code if it's derived from yours, allowing individuals to use a product but not allowing business to use it (businesses can use it under a different - likely paid for license), or requiring attribution or acknowledgement that they used your code.
There is an argument for fair use if it counts as a substantial derivative, which is a different discussion from why people make it publicly viewable without making it flat out public domain.
One example of restrictive but public licenses include requiring others to share their source code if it's derived from yours, allowing individuals to use a product but not allowing business to use it (businesses can use it under a different - likely paid for license), or requiring attribution or acknowledgement that they used your code.
There is an argument for fair use if it counts as a substantial derivative, which is a different discussion from why people make it publicly viewable without making it flat out public domain.