To think in this context is an idiomatic expression used to express surprise, dismay, or ironydismay and thus is not constrained by typical grammar rules about infinitives as subjects.
As a whole, its meaningits meaning is along the lines of
"It's surprising that..." or
"It's shameful that..."
It doesn't mean "Thinking that..." as it would in a sentence like "To think [that] the moon is made of cheese is incorrect."