Each has a different reason. The dollar is the world's funding and reserve-currency, so a scramble for liquidity is a scramble for dollars. The franc reflects a long record of low inflation and a large external asset position. The yen's status comes largely from its role as a funding-currency: when leveraged positions are cut, borrowed yen is bought back, a process described in carry-unwind.
Haven status is behavioural, not guaranteed. The yen weakened during some risk-off episodes when the rate gap dominated, and the franc's haven bid was actively fought by the central bank for years before swiss-franc-unpeg.
For a trader the useful part is the pairing. Risk-off is expressed cleanly as long yen or long franc against a commodity-currency, since both legs move the same way.
Example: an equity index falls 4% in a session. AUD/JPY drops 2.3% while AUD/USD drops 1.1%, because the cross combines the risk-sensitive leg with the haven leg.
Related: flight-to-quality, funding-currency, swissy, risk-on-risk-off