Each edition has different rules with respect to this. D&D 5e removed all restrictions and made alignment a general thing for characters. There is flavour text indicating which classes tend to do what, however the customization aspect allows for things like chaotic-evil Paladins.
For other editions, the easiest way to find out is to look up the class you're interested in and whatever edition you are playing.
For instance: Google search 3.5 Monk to find out that Monks need to be any lawful category.
As an example, D&D 3.5 has alignment rules for several classes such as Paladin, Barbarian and Druid.
Barbarians (any non-lawful); Paladins (lawful good); Druid (any neutral)