This is both a modern custom and an ancient one at the same time.
Most accounts link the kirkin’ o’ the tartan back to the 18th century history and the fact that after Bonnie Prince Charlie’s forces were defeated by British forces in 1746 at the Battle of Culloden, wearing tartans and playing bagpipes were forbidden in Scotland for many years.
Wearing or even displaying tartans was punishable by death. During those years, some Scots wore concealed pieces of their tartan when attending church. At a particular point in the worship service, the story goes, they would secretly touch their hidden tartan cloth, and the minister would offer a blessing.
But taking that history and making it into a custom is a 20th century phenomenon, and started in the USA.
Dr Peter Marshall was a Scot who was a Presbyterian minister in Washington DC and chaplain to the US senate. In the early years of the Second World War he held prayer services at which money was raised for war relief. At one in early 1943 he gave a sermon entitled “The kirkin’ o’ the tartans”. The custom was revived to instil pride among Scottish-Americans in their Scottish homeland.
Kirkin’ is from the Scots word kirk, meaning church, and in this context means blessing.