Typically, you can claim Original Routing Credit (ORC) for the flights you were originally booked on. If you are rebooked on an airline on a different alliance, you can claim duplicate credit for membership in that alliance too.
Useful thread for AA: https://www.flyertalk.com/forum/american-airlines-aadvantage/1586992-faq-involuntary-reroute-original-routing-credit-orc-master-thd.html
Just to add my personal experience. I've been re-routed multiple times on AA flights intended to be credited to BA, and always received original BA credit. I've been re-routed to Delta and received both original BA credit as well as Flying Blue credit.