That is because code contracts are not the same as compile time asserts. They are still runtime code but they also come with a static analysis rule set that you can enable in your projects to do what you are looking for.
Take a look at this question which looks like it already answers this issue very well: Contract.Assert do not throw compilation error