As The Merriam Dictionary says it means to to get into trouble because of failing to do what is required by (the law, a rule, etc.) For example:
After leaving school she fell foul of the law and spent time in jail.
I have been trying to find something on its origin on the internet, but I cannot find anything. To me as a non-native english speaker the phrase sounds so odd that I am desperate to find out its origin.