Differentiation is a linear operator so you are basically asking when a real function (like sine) can be applied to an operator
to obtain a new one. This is precisely the concept dealt with under the name "functional calculus" about which there is a vast literature (as one of the fundamental topics in operator theory).
Your question is formulated in a rather vague manner and it would be necessary to make it more precise in order to answer it in a rigorous fashion.
It will be more enlightening to start with the final question which can be stated in the form: for which functions $g$ can we define $g(T)$ for a suitable operator $T$? Your operator is that of differentiation but for reasons which will soon be obvious, it is appropriate to replace it by $i \dfrac{d}{dx}$ (which we will denote by $T$). This involves only a slight notational adjustment.
The short answer to your question (or rather, one of many short answers) is that this is valid for the case where $g$ is a measurable real function on the line and $f$ is in $L^2$ there. These conditions hold, of course, in your initial example.
The reason is that $T$ can be regarded as a self-adjoint operator on this Hilbert space and for such operators the functional calculus is valid for any measurable function on its spectrum which in your case is the whole line. A vital point is that we are talking here of unbounded self-adjoint operators which are necesssarily not defined on the whole Hilbert space so that care is required in the definition (in particular, that of its domain of definition). This is intrinsic to your case--there is no sensible way to choose a Hilbert space of functions on the line so that your operator is a continuous linear operator thereon.
This is a consequence of the mathematical formulation of the Heisenberg uncertainty principle.
In general, in order to make your question precise, you have to specify a space of functions on which your operator acts. For example you can choose a domain of definition and a smoothness condition for them. It is natural to choose as starters $[0,1]$ or the line for the former and the $L^2$ spaces for the latter.
This give us two examples, the one mentioned above and the discrete version on $[0,1]$. Here it is necessary to add a boundary condition to the domain of definition of $T$ in order to obtain an operator which is not just formally self-adjoint but self-adjoint in the sense of operator theory in Hilbert space. The usual one is that of periodicity.
One can then give precise answers to your final question in this context. As regards your original question about explicit calculations, there are many ways to do this in the abstract setting but this is not the time and place to detail them. One classical method is to use the spectral theorem to diagonalise them, i.e., to express them as multiplication operators on $L^2$-spaces. In your case, this is carried out using the Fourier transform resp., Fourier series.
Warning: The natural way to do this in the FT case is to diagonalise your operator using the Fourier transform resp. Fourier series. This involves applying the former to exponential functions. This site is full of dire warnings that the latter are not tempered distributions and so the FT is not applicable--a classical example of confounding necessity and sufficiency of conditions (rather disconcerting in a maths forum). It has been known since the founding years of distribution theory that one can apply the FT to ANY distribution on the line, in particular to exponential functions. The result is an analytic functional, that is, a functional on a space of entire functions. In your case, the objects which arise are Dirac functions with singularities in the complex plane--in your case $i$ and $-i$. The requisite formulae
can be found by googling--these tend to use purely formal computations but the results are usually correct--they can be justified rigorously by using methods of distribution theory.
This is a rather cursory exposition but I would be happy to provide more details and references if requested.