Premultiplication by a quaternion q, or postmultiplication by q, represents a linear transformation. This is because multiplication distributes over addition, and commutes with scaling by real numbers.
If you're into modules, this result can be generalized to any ring R. Pre or post multiplication by q implements a left or right R module homomorphism on the quaternions, when viewed as a free R module. Furthermore, these module homomorphisms can be composed. If p and q are two quaternions, Apply p, and then q, which is the same as multiplying by pq. Also,(p+q) implements a transformation that is the sum of the transforms implemented by p and q. Therefore the quaternions form a subring inside the ring of endomorphisms on 4 dimensional space. But I digress.
Some linear transformations cannot be implemented in this way. Let f() fix x and i, and rotate the jk plane 90°. That is, f(j) = k and f(k) = -j. This is in fact a rigid rotation. If it is realized by some quaternion q, then 1*q = 1, since the x axis remains fixed. Thus q = 1, and the transfoormation fixes everything, which is a contradiction.
Let q = a+bi+cj+dk and consider multiplication by q. What does this do to the basis elements? If we know, we can build the corresponding matrix that implements the transformation. Here is the matrix associated with postmultiplication by q.
a | b | c | d |
-b | a | d | -c |
-c | -d | a | b |
-d | c | -b | a |
Check every pair of rows, and show that this matrix is orthogonal. The determinant of such a matrix is the product of the lengths of its row or column vectors. The length of each vector is the square root of the norm of q, so the determinant is ± the norm squared. The transformation is a rigid rotation or reflection iff the norm is 1, iff q is a unit, iff q lies on the unit sphere in 4 space.