"Some companies I work for write the contract that all code written while employed belongs to the company."
That's why - because it shows evidence of code you produce, are interested in coding on a personal level (as opposed to doing it purely for the paycheck), how you solve problems, how you document code, how well you communicate with others etc.
It does feel like having an active Github is almost a requirement these days - but there are plenty of people who feel this is unfair, see for example -> http://www.ashedryden.com/blog/the-ethics-of-unpaid-labor-an...