A key is kind of a harmonizing tool (I guess you’d call it a tool). It’s basically a set of notes that work together. Major and minor keys follow different rules to find notes that harmonize. They also produce sounds that are connotationally different in Western music. Minor keys are generally viewed as more dissonant, lonely, and sad. Major keys are generally viewed as brighter and uplifting.
Music can modulate between keys, but I don’t think you often change between a major key and a minor key because the tonal shift is pretty great. An equivalent would be something like starting to tell an uplifting story about a relationship and abruptly shifting to a brutal breakup. So when you modulate you generally stay inside the same major or minor frame. (ETA I am wrong about this as pointed out here.)
For some examples How Far I’ll Go is in a major key. Major keys kind of flow together. Notes are full steps apart and feel like a smooth flow. Crazy on You is in a minor key. There are more half-steps in a minor key and you feel a kind of disjointedness.
If you take How Far I’ll Go and turn it into a minor key version you get a darker feeling. Granted there are some other changes to this song, but the key is an important one.
This video digs into some of the theory around keys and might be of interest.
I’m sure a real musician could explain this better, but I think this is a decent start.