Mastery grades depend on your percentile performance relative to all other players on that particular champ in that particular role.
Those in others roles and on different champions have no influence on your grade, and only the performances on the same champ in the same role are comparable. There no absolute requirements, just how to compare to others, so if you play a champ/role combo that everyone does horrible on, and you do slightly less horrible (but still 'bad' by most absolute standards) it's quite possible to get an S+. That said, theres mains for pretty much every champ/role combo, so you generally still have to do reasonably good. Some champ/role combinations require you to be really good though.