'I can play the piano,' he thought.

Literal

I [topic-は] piano [subject-が] can-play [explanatory-のだ], [quotative-と] he [topic-は] thought.

An unusual sentence mixing first and third person — 僕はピアノが弾けるのだ is the quoted thought ('I can play the piano'), and と彼は思いました frames it as what 'he' thought. This is Japanese indirect-style quotation where the quoted content retains the original speaker's perspective (僕). Polite past ~ました.