Leviticus 11 lays out the animals that are considered clean and unclean for the Jewish people. Although winged insects that walk along the ground are considered unclean, winged insects that walk along the ground and have jointed legs so they can jump, are considered clean. Locusts fall under this category and so John the Baptist would have known that he was permitted to eat Locusts under the law. If you read Leviticus 11:20-23, you will see that it specifically mentions that all kinds of locusts are permitted to eat.
Leviticus 11:20-23 – “You must not eat winged insects that walk along the ground; they are detestable to you. 21 You may, however, eat winged insects that walk along the ground and have jointed legs so they can jump. 22 The insects you are permitted to eat include all kinds of locusts, bald locusts, crickets, and grasshoppers. 23 All other winged insects that walk along the ground are detestable to you