I was able to find the solution (big thanks to M.). I had to put the track source IP directive:
http-request track-sc0 src
after my rate limiting rule
http-request return status 299 content-type “text/plain” lf-string “Rate limit exceeded.” if { sc_http_req_rate(0) gt 50 }
That way, the request is first evaluated against the current rate before it contributes to the counter. If it passes, it is then tracked and included in the stick-table rate count.