I presume you're talking about English/British monarchs so I am answering in that vein.
I believe Henry VIII was the first to have this title, purely ceremonial. It was conferred upon him by the Pope after he wrote a book/pamphlet which defended the sacraments and the authority of the Pope. Now obviously Henry later broke completely with the Catholic Church and was excommunicated!
In the modern day the British Monarch uses Defender of the Faith as a subsidiary title but it does have a purpose. The monarch is the head of the Church of England and this title recognises that. It recognises that none but God is above the monarch and all - including the Archbishop of Canterbury (notionally the highest office within the CofE) - and underlings of the monarch.