And thus do you find: Whenever a miracle is performed for Israel, that miracle, as it were, is before Him — "The L–rd is my miracle." (Isaiah 63:9) "In all of their afflictions, He was afflicted." Joy to Israel — Joy to Him. (I Samuel 2:1) "I rejoice in Your salvation!"
When Israel Experiences Joy, That Joy Belongs to God as Well
Mekhilta Tractate Amalek 2:46