Hello Lydia,
As previously said , A is correct here!
I wonder how come you say it should be B?!
Unless B= " caught on"
and you made a typing error.
Then it is :
"That building caught on fire worried them."
In this case it would be more appropriate to use B because "caught on fire" indicates that the building started to burn with flames and that would worry them, as how to quickly save the situation and extinguish the initiating fire before something more unpleasant might happen .
Number A " on fire" on the other hand means the house is already burning, and their feeling at such a sight wouldn't be described precisely as "worry".It presents then a higher degree of anxiety and fear than merely worrying. So A wouldn't be that appropriate in this case.