My guess is that at some point in the past there was a second switch there, which was connected to those wires in the black tape. Maybe there is a light that is currently controlled by one switch, but previously it was also controlled by a second switch here?
Be sure to turn the power off before doing anything. In particular, note that you don't know which circuit those taped-up wires are connected to. Don't just turn off the lighting circuit, turn everything off.
Assuming that you just want to replicate what you have now, you can just connect your new switch to the red and black wires as currently.
Personally, I would investigate the taped-up blob and see what is connected to what, and how. In particular, if there are wires that are just twisted together you could reconnect them using a proper connector. I'm also curious about the earth wire, which should probably be connected to the earth terminal in the back box even if nothing else from that cable is connected to anything. But you might choose to leave it all as it is.
When you reassemble, push the black grommet back into the hole in the back box.