How to mute microphone in 2-way communication when the speaker is active?
The standard way to deal with this situation is to use something called a "two to four wire converter".  This is ancient terminology dating from early days of the telephone industry but the techniques are still in use today.

What this circuit does is to subtract the local microphone signal from the speaker.  There are fully-analog versions of this but modern implementations (cell phones, etc) use digital techniques.

Google will teach more than you want to know about this technology but you should easily find an analog implementation using only a couple of op-amps.

Most analog versions require you to manually find the null.  However, the null is normally stable and you should need to adjust it only once.

Using this technique allows you to have a fully duplex link (talk and listen at the same time).