Either sentence could work - There is very little effective difference between these two phrasings.
1.The sudden change in temperature can cause rocks to shatter.
...in temperature draws my attention to the ambient/external temperature around the rocks. Their surroundings have changed temperature, which we presume will cause the rocks to change temperature and shatter.
- The sudden change of temperature can cause rocks to shatter.
In a very subtle way, this suggests that the internal temperature of the rocks has changed.
Neither of these interpretations is totally rigid, though - I can see them being used interchangeably with no lost understanding.
More important. Unless these sentences directly follow a specific cause of the temperature change, you probably don't want the direct article, the. For example:
It is scorching hot here during the day, but every night, the fish company dumps a huge truck full of crushed ice on the landscaped gravel. The sudden change of temperature can cause the rocks to shatter.
We already know about the temperature change being referred to.
But when we don't know the cause of the temperature change:
These rocks are resistant to being crushed by heavy weights, but they are sensitive to other factors. A sudden change in temperature can cause the rocks to shatter.
We aren't talking about a specific temperature change - any will do. This could also be written:
These rocks are resistant to being crushed by heavy weights, but they are sensitive to other factors. Sudden temperature changes can cause the rocks to shatter.
AmE