Formalism, n.
The practice or the doctrine of strict adherence to, or dependence on, external forms, esp. in matters of religion. Official formalism. Sir H. Rawlinson.
Shades of meaning
Fernald has no entry of its own for formalism; he lists it under hypocrisy.
Where he writes about it:
Pietism, originally a word of good import, is now chiefly used for an unregulated emotionalism; formalism is an exaggerated devotion to forms, rites, and ceremonies, without corresponding earnestness of heart; sham (identical in origin with shame) is a trick or device that puts one to shame, or that shamefully disappoints expectation or falsifies appearance. — from hypocrisy