More broadly, a lot of people like to point out wild 20th century chords in baroque music, but they really didn't think in terms of chords, and as such these pseudo-chords don't have the same function that modern versions of chords do. In particular, Scarlatti was a prolific user of the partimento method of composition, which is a slightly of abstracted version of counterpoint, and his sonatas are pretty good examples of pieces written with this in mind. The method revolves around intervals and movement between voices rather than chords. It's normal for someone thinking in counterpoint to produce some very "modern" "chords" because that's a common consequence of following nothing but voice leading to produce a piece of music.
https://en.wikipedia.org/wiki/Partimento
See also Rick Beato mis-analyzing Bach's counterpoint as containing a very "modern" maj7#5 chord: https://www.youtube.com/watch?v=d1f_tzBx6ko&t=1s