Is it possible for squawk to change automatically in emergency situations?
Whether or not an airlines is in an emergency situation is not a black or white question. There are millions of different internal and external factors that come into play, any combination of which may or may not be considered an emergency. No computer can be programmed to accurately and consistently calculate whether or not a flight is having an emergency situation - in fact, that's one of the main reasons we still have real, live pilots seated up front.

Could you program a computer to detect a few obvious emergencies (total loss of power, rapid decompression, fire etc.)? Sure. But it wouldn't be able to detect everything.

What's more, setting squawk 7700 is not always the best cause of action in an emergency. In fact, most of the time a flight will already be in contact with ATC and have an assigned discreet transponder code - in such a situation, setting squawk 7700 will often have little or no effect, since you can talk directly to ATC on the radio and explain what's going on. You might even risk ATC losing identification if you start changing your squawk code out of the blue, which could add additional risk. In other cases, squawking 7700 can be beneficial, for example if you are not talking to ATC - or maybe the frequency is very busy and you can't get through - or maybe you don't have time to call ATC, but still need their attention (rapid decompression). ATC might also request that you squawk 7700, to reduce workload on their end.

So to summarize, no, a computer would not be able to necessarily detect when a flight is having an emergency situation. And even if it could, setting squawk 7700 might not even be useful.