I can confirm, that this bug exists in the newest 1.18.1 version.
How I tested it:
I equipped 4 piecies of armor all with protection IV and Thorns III enchants
I spawned the guardian
I let him shoot me with the beam 30 times - I did not notice him take any thorns damage (no damage animation)
After I could hit him another 30 times with bare hand before he died (waiting each time to recieve spike damage from him).
Conclusion - guardians in 1.18.1 are not affected by Thorns enchantment for both range (beam) and melee (spike) attacks.
Please, reopen this issue.
I can confirm, that this bug exists in the newest 1.18.1 version.
How I tested it:
I equipped 4 piecies of armor all with protection IV and Thorns III enchants
I spawned the guardian
I let him shoot me with the beam 30 times - I did not notice him take any thorns damage (no damage animation)
After I could hit him another 30 times with bare hand before he died (waiting each time to recieve spike damage from him).
Conclusion - guardians in 1.18.1 are not affected by Thorns enchantment for both range (beam) and melee (spike) attacks.
Please, reopen this issue.