It is not a declension of von or in. It is a contraction and fusion of the preposition and the article together into a single word. Thus, the entire thing has nothing to do with grammar.
It is a feature more present in spoken and even more in colloquial language, where often other prepostions fuse in the following articles, too. To give just a very small number of examples:
in’n from in + den
abm from ab + dem
unters from unter + das
These contractions are never mandatory, it is always possible to use the long form, e.g. to give emphasis. It is not possible to use them when dealing with relative pronouns, e.g:
Das Lied, von dem ich gehört hab.
However, while never being mandatory, the forms im and vom are so common that they are even considered acceptable/encouraged in formal written language. So it would be better style to use them. In fact, especially im and vom are so common that not using them is often identified as an especially strong from of emphasis.
A: Ich mag es, wenn es in dem Winter kalt ist.
B: In welchem Winter?
(Example inspired by Carsten S in a comment. It is so unusual that one feels prompted to ask which winter since it is so close to in diesem Winter.)
We can distinguish between a declension and a contraction by the following thought experiment: Consider it to be a declension. Then, these forms should also turn up in some way when switching from a definite article to an indefinite one. However it is:
Ich habe im Park eine hübsche Blume gesehen.
Ich habe in einem Park eine hübsche Blume gesehen.