While spray foam does rapidly expand and harden, these are two different steps in the process, and they don't occur at the same time. When the foam first begins to bubble and expand, it's still mostly in its liquid stage. It does not have have the strength necessary to push against a wall and create enough pressure to crack it. Once the foam has finished expanding and starts to dry, its size does not change and your walls are left unharmed.
There are cited benefits to using spray foam in your walls. Far from creating cracks or other problems, spray foam insulation may actually be able to make your walls stronger and more resistant to moving. This may help prevent future cracking issues due to foundation shifts or other reasons. In many cases, the foam is designed to fill in and prevent cracks.
Spray foam is designed to adhere to most substances it's sprayed onto. This include wood, metal and other plastic-based materials. However, adherence is not always assured. Sometimes, coatings can interfere with the ability of the foam to attach to a surface. Occasionally, the foam is mixed improperly, which can result in the hardened foam pulling away from a surface. This can creates gaps and cracks in the insulation itself, but it should not harm the integrity of your walls.
Timing during construction can be important when it comes to spray foam. If you want to install the insulation in your walls, make it part of the construction process, while the walls are being built. While spray foam can be applied inside existing walls, it is much more difficult. The walls may not suffer damage, but there will be gaps that contractors cannot reach.