The general scriptural rule is that as long as one is not aware of an impurity he is unaffected by that impurity.
You were not aware of the Sutak impurity at all at the time you visited the temple and hence you were yet to be affected by it. Once you receive the news of the death the impurity starts affecting you.
32 These six means of purification are recommended for creatures:
time, fire, purifying the mind, water, looking at the sun, and being
unaware that something is impure
Vashishta's Dharma Sutras 23.32
Also, another thing to consider here is that death happened in a distant place and the news arrived to your family later and in such cases the rules of Sutak are different from the usual ones. Have a look at:
When a child less than two years old dies or when there is a
miscarriage, the period of impurity of those belonging to the same
ancestry lasts for three days; 35 according to Gautama, they become
pure immediately. 36 When someone living in a distant region dies and
the news arrives after ten days, the period of impurity lasts for one
day.
Same scripture 4.34-36
EDIT:
You have clarified (in comments) that you were aware of the news of death but was not aware of the fact that the impurity applies on you.
I would think even in that case my answer holds good because the impurity has not affected you as long as you were not aware of it. So, I am not deleting the answer.