Yes, a plant can be both male and female. We call these "hermi" plants (for hermaphidite). That is a term stating both male and female gender, human and plant.

Hermi happen when the plant goes through severe stress, or light leaks. What you can do is clip off the male plant matter daily so the pollen doesn't get released, but that takes a lot of time and patience. Or, you could just let it grow and get seedy bud. Either way, it's not a good thing.

Peace