I will address the second question primarily, because there is an important point here about the notation.
Right from the beginning, the following statement
$$\hat{p} = -i\hbar \partial_x$$
doesn't makes sense, especially when you then go to try and act on abstract ket vectors. The operator $\hat{p}$ is an abstract operator acting on abstract ket-space whose representation in position-space is given by $\frac{\hbar}{i}\frac{\partial}{\partial x}$. You cannot act with $\frac{\hbar}{i}\frac{\partial}{\partial x}$ on kets because these objects live in different worlds.
To explain, note that if we have an abstract ket (quantum state) $\lvert \psi\rangle$, we can compute its expansion coefficients in a basis $\lvert \varphi_n\rangle$ by by computing the inner products $\langle \varphi_n | \psi\rangle$. Then, you can think of $\langle \varphi_n | \psi\rangle$ as the $n$'th element in a column-vector representation of $\lvert \psi\rangle$, i.e.,
$$
\lvert{\psi}\rangle \to
\begin{bmatrix}
\langle \varphi_1 | \psi\rangle \\
\langle \varphi_2 | \psi\rangle \\
\langle \varphi_3 | \psi\rangle \\
\vdots
\end{bmatrix}\,.
$$
In roughly the same way, we can expand the vector in the position eigenbasis (i.e., $\{\lvert x\rangle\}$) by computing the inner products $\langle x | \psi\rangle$. Very roughly speaking, you can think of $\langle x | \psi\rangle$ as an element in a column-vector representation of $\lvert \psi\rangle$, just as above. The problem is that we have continually-many $x$'s, and so a column-vector representation (to the extent that it even makes sense) is computationally intractable. For that reason, we think of $\langle x | \psi \rangle$ as a function $\psi(x) = \langle x | \psi \rangle$ and call it the wave function, although we should really be thinking about it as the position-space representation of the quantum state $\lvert \psi\rangle$.
Now, in order to act with $\hat{p}$, we need to (1) know how $\hat{p}$ acts on the arbitrary state $\lvert\psi\rangle$ (which is usually not possible), (2) work in momentum space, or (3) work in position-space. The latter is what is relevant here. It turns out that the proper way to understand things is as follows:
$$
\langle x \lvert \hat{p} \rvert \psi \rangle
=
\frac{\hbar}{i}\frac{\partial}{\partial x}\psi(x)\,.
$$
In words, the position space representation of the state $\hat{p}\lvert \psi\rangle$ arrived at by acting with the momentum operator on the quantum state $\lvert \psi\rangle$ is exactly the derivative of $\psi(x)$, up to some constants. We can derive this by appealing to option (2) above, working the momentum basis and using the commutation relation $\hat{x}$ and $\hat{p}$ or, equivalently, using the Fourier relationship between momentum-space and position-space.
In any case, all of that is to say that something like
$$
\hat{p} = (-i\hbar \partial_x)(\sum_{a'}\vert a' \rangle \langle a' \vert) = -i\hbar(\sum_{a'}\vert a' \rangle \partial_x \langle a' \vert)$$
doesn't make sense, because you are mixing two different representations together, which makes things fall apart.
In the derivation of the propagator done in Sakurai, that basis $\{\lvert a \rangle\}$ is assumed to be the eigenbasis of the Hamiltonian $\hat{H}$, and the abstract operator $\hat{H}$ is allowed only to act on kets $\lvert a\rangle$ and never on the dual vectors $\langle a\rvert$ or anything else. Once the matrix elements
$$
\langle a'' \lvert e^{-i \hat{H}t/\hbar} \rvert a' \rangle
$$
have been computed, then they can be moved anywhere, because they are numbers (complex numbers, sure, but still numbers) and not operators.
To parallel that discussion with the momentum operator, consider the eigenbasis $\{\lvert p \rangle\}$ of the momentum operator, such that
$$
\hat{p}\lvert p \rangle = p \lvert p \rangle\,.
$$
Then, to figure out what $\hat{p}$ looks like explicitly in terms of its eigenbasis, we can write
\begin{align}
\hat{p} &= \left(
\int_{-\infty}^{\infty}dp'\,\lvert p' \rangle\langle p' \rvert
\right)
\hat{p}\left(
\int_{-\infty}^{\infty}dp\,\lvert p \rangle\langle p \rvert
\right)
\\
&=
\int_{-\infty}^{\infty}dp'\,\lvert p' \rangle\langle p' \rvert
\int_{-\infty}^{\infty}dp\,\hat{p}\lvert p \rangle\langle p \rvert
\\
&=
\int_{-\infty}^{\infty}dp\int_{-\infty}^{\infty}dp'\,
\lvert p' \rangle
\langle p' \rvert\hat{p}\lvert p \rangle
\langle p \rvert\,,
\end{align}
and since
$$
\langle p' \rvert\hat{p}\lvert p \rangle
=
\langle p' \rvert {p}\lvert p \rangle
=
p\langle p' | p \rangle
=
p\delta(p-p')\,,
$$
this becomes
\begin{align}
\hat{p} &=
\int_{-\infty}^{\infty}dp\int_{-\infty}^{\infty}dp'\,
\lvert p' \rangle
p\delta(p-p')
\langle p \rvert
\\&=
\int_{-\infty}^{\infty}dp\,p
\lvert p \rangle
\langle p \rvert\,.
\end{align}
Alternatively, if we want to see what $\hat{p}$ looks like explicitly in the position representation, we would use two resolutions of the identity in terms of the position eigenstates instead, and use the fact that
$$
\langle x' \lvert \hat{p} \rvert x\rangle
=
\delta(x-x') \frac{\hbar}{i}\frac{\partial}{\partial x}\,,
$$
a derivation that you'll see in Sakurai, and in the process of the derivation, you'll see that $\frac{\hbar}{i}\frac{\partial}{\partial x}$ will only be acting on objects that look like $\langle x | \psi \rangle$ and not on kets or bras or anything else.
(Note that the last equation is equivalent with the statement that
$$
\hat{p} = \int_{\infty}^{\infty}dx\,\lvert x\rangle \frac{\partial}{\partial x}\langle x \rvert\,,
$$
where the $\frac{\partial}{\partial x}$ is understood to act to the right, usually after we have applied this to a ket $\lvert \psi\rangle$.