Generally, this kind of phenomenon seems to be called 格の交替 in Japanese linguistics.
中上級を教える人のための日本語文法ハンドブック says this happens (p185)
- 出来事を描く立場が変わる場合
- 出来事の状態的な側面を描く場合
1 is the one that happens by changing active/passive. Your case is (probably) included in 2.
If you google a keyword like "ヲ格 ガ格 交替", then you see lots of research articles - so it is beyond my knowledge to give a comprehensive answer.
The following are the を/が examples with 好きだ
- 私は甘いものが好きだ I like sweets
- 私が甘いものを好きだということを彼は知らない He doesn't know that I like sweets.
Maybe it is not exactly about 出来事の状態的な側面, but I feel 1 and 2 have difference of perspectives.
- 1 says something about sweets so 甘いもの is treated like a subject (= use of が)
- 2 says something about I (due to the enclosing by ということ), so that 甘いもの is treated as an object and 私 as the subject.