Why are lynching and mob-justice so popular in India? What is wrong with their law and law enforcement?
Usually, lynching and mob justice are due to (1) a lack of faith that the formal legal system is likely to produce a just result as viewed from the perspectives of the community norms of the potential participants (whether or not this is true) and (2) there is also confidence (again, not necessarily accurate) that the people carrying out the vigilante punishment will escape unscathed.
Often (1) and (2) have a common cause, and in India, the pace at which serious criminal charges are handled in the judicial system is often glacial, and there is a perception that authorities may often be corrupt or incompetent.
In your first two examples (the rapist and the murderer), the public would probably be satisfied if they knew with confidence that the sentences prescribed by law for those offenses were carried out, although these were both historically capital offenses under British colonial law and pre-British law in most places for long periods of time in India, and community norms may not have kept up with human rights reforms that have led to non-capital punishments for these serious felonies. (Also, mob justice tends to be a death or corporal punishment or nothing affair because mobs lack the means to carry out prolonged incarceration.)
In the last two examples (offenses against cows), there probably is a big gap between the secular property crime punishment authorized by law for harming a cow (which may even be regulated and legal in recognition of India's religious diversity) and Hindu religious norms which see this as a grave violation of sacred law that should carry a very serious punishment. Thus, the disconnect between formal sanctions authorized by law and the norms of those who participate in and/or tolerate this kind of vigilante activity may be great. Lack of will to prosecute vigilantes rather than lack of competence, may be an important factor here.
The fact that India's penal codes are derived from the British colonial model, even though India has been independent for more than half a century is no doubt part of this disconnect. Inertia is a powerful force in the law. And, while these laws weren't originally created to reflect local community values, once they were enacted they were probably assimilated as just by elite lawyers/legislators to a great extent even though these views weren't necessarily shared by the ordinary person.