It is transfer of malice. Though S.301 talks only with respect to homicide. It is applicable with respect to other offences as well. For eg : Hurt, Kidnapping. The rationale for such liability is that the person i.e the author of crime does an act/ommission i.e actus which is reus that is forbidden by law coupled with the necessary mens rea. If its effect falls upon a person other than the person intended, the person's moral culpability is the same. In this regard it can be seen as akin to Criminal Attempt where offender does whatever he could - but consequence does not result. Here he has done all he could - though it falls on somebody else. However only as much malice/motive would be transmigrated as he earlier had and there should be no break in transaction. In the case of M.S.Moorthy v. Public Prosecutor - presents an interesting example where A gave poisoned halwa to B - who further gave it to X - Now this act would be attributed to him, his earlier intention was to kill. However if his intention was only to make B somewhat uneasy and he poisoned it very slightly - however X to whom it was subsequently passed was allergic to the same and dies. A would only be liable for hurt by poison etc. Hence Initial Mens Rea is the germane consideration.
In the above example if B knowingly gave the halwa to X - who dies in consequence - then B would be liable for 511 r/w 302 - and B for 302.