Yes, they know it from x-rays, but some still don't tell them. They hide it either knowingly or unknowingly. I personally think that the ethical and responsible thing to do is to tell them about your treated TB history during the medical assessment at the IOM and follow their instructions afterwards. It's ethical.
It looks like they consider all old healed scars as past TB infection whether you tell them or not or whether those scars are from past TB infection or something else.
I had extremely mild cough for a couple of days in 2012, nothing else. I could play a lot of sports, football, cricket, badminton, running, etc. As I am always careful, I consulted my doctors immediately here in 2012, they have checked for TB, digital x-rays, CT scan, etc. They were fine and I had no signs and symptoms of TB. As I said, not even the only cough was persistent, but one doctor still put me on a 6-month course for TB and two other doctors said I shouldn't have taken it because I didn't need it in the first place (I didn't have TB). I think I was misdiagnosed according to x-rays and two doctors, but I took a complete 6-month course anyway on the recommendation of the other third doctor.
I did develop a small scar after the treatment in 2012, I'm not sure if that appeared as a result of antibiotics (the 6-month TB course I took) or something else. Anyway the scar has been 11 years old. I am an Afghan refugee living in Pakistan, I applied as a refugee in May 2022 and had medical appointment on 6th March 2023. I told all that I mentioned above during the medical assessment at the IOM. They then requested me to have a sputum test. I gave all 3 samples, each 1 hour apart on 7th March and my next appointment is scheduled for 8th June 2023. It apparently delayed my visa for about 3 months.