Statement. Let $R$ be a ring, $M$ be an $R$-module and $(M_i)_{i\in I}$ be a family of $R$-submodules of $M$. Then for every $R$-linear map $f$ defined on $M$, $$f\left(\sum_{i\in I}{M_i}\right)=\sum_{i\in I}{f(M_i)}.$$
Proof. For each $i\in I$, because $M_i\subseteq\sum_{i\in I}{M_i}$, it is clear that $f(M_i)\subseteq f(\sum_{i\in I}{M_i})$ as well. This shows that $$\sum_{i\in I}{f(M_i)}\subseteq f\left(\sum_{i\in I}{M_i}\right).$$
Conversely, let $y\in f(\sum_{i\in I}{M_i})$. Then $y=f(x)$ for some $x\in\sum_{i\in I}{M_i}$. In this case, we can write $$x=x_{i_1}+\cdots+x_{i_k},\quad\text{where}~x_{i_j}\in M_{i_j},~j=1,\ldots,k,~i_1,\ldots,i_k\in I.$$ As a result, \begin{align*} y=f(x)&=f(x_{i_1}+\cdots+x_{i_k}) \\ &=f(x_{i_1})+\cdots+f(x_{i_k})\in\sum_{i\in I}{f(M_i)}. \blacksquare \end{align*}
It seems that the above proof is very straightforward, but I still want to verify it here in case there were any counterexamples.
Meanwhile, provided it is correct, I wonder if it follows from some more general results, as I have no impression that any textbook or monographs has stated that explicitly.
Note that the second inclusion can also be proved without taking elements, just as you did with the other one:
For each $i \in I$, $M_i \subseteq f^{-1}(f(M_i)) \subseteq f^{-1}(\sum_{i \in I} f(M_i))$; so, $\sum_{i \in I} M_i \subseteq f^{-1}(\sum_{i \in I} f(M_i))$, which means that $f(\sum_{i \in I} M_i) \subseteq \sum_{i \in I} f(M_i)$.
The thing is that this result only needs the following two facts:
In other words:
The general result that you're looking for is:
You already have the proof of this.