This Wikipedia article indicates that he was executed because the ruler wanted to strengthen his grip on power:
According to the official account of the Mughal Empire, written 107 years later by Ghulam Husain of Lucknow in 1782,
Tegh Bahadur, the eighth successor of (Guru) Nanak became a man of authority with a large number of followers. (In fact) several thousand persons used to accompany him as he moved from place to place. His contemporary Hafiz Adam, a faqir belonging to the group of Shaikh Ahmad Sirhindi's followers, had also come to have a large number of murids and followers. Both these men (Guru Tegh Bahadur and Hafiz Adam) used to move about in the Punjab, adopting a habit of coercion and extortion. Tegh Bahadur used to collect money from Hindus and Hafiz Adam from Muslims. The royal waqia navis (news reporter and intelligence agent) wrote to the Emperor Alamgir [Aurangzeb] of their manner of activity, added that if their authority increased they could become even refractory. — Ghulam Husain, Mughal Empire records
Tegh Bahadur, according to Mughal Empire records, was collecting money from Hindus (which is kind of treasonous at that time).
This book states he was killed because he didn't convert to Islam.
Why was he killed?