PS1 escaping can get confusing, TLDR:
1 '$()' '${}' "\$()" "\${}" run every time the prompt is printed.
2 "$()" "${}" run in the asignment.
3 '\$' acts as the PS1-specific \$ sequence.
4 "\$" may act like #1 or a literal '$' depending on what follows.
Also important: https://www.youtube.com/watch?v=ngLwml9XI-I&list=PLWBKAf81pmOaP9naRiNAqug6EBnkPakvY&index=252