How do Computer Algebra Systems work?
Note: For this answer I chose to assume that the question was somewhat
naive, since, as remarked by @D.W. in his comment, the OP should
otherwise search for himself in wikipedia and other places on the web,
and the spectrum of problems and techniques is far too wide for an
answer here. So I am focussing on the fundamental aspects, obvious to
a seasoned computer scientist, but somewhat magical for someone with
less technical experience, and seeming to border artificial
intelligence, when it is often just the application of appropriate
recipes (well, often complex ones). One meta-remark: users who ask
questions should give some information regarding their experience (or
their age, as a weak indicator). It is often difficult to assess the
level appropriate for an answer.

A fundamental question is whether there is any difference between
numerical computation and algebraic manipulation.

As a computer scientist (to be ?) you shold more than anyone else be
aware that all that is done by the computer, or by the mathematician,
is to manipulate representations of abstract entities.

You learn in "algorithmics and data structures" that to deal
efficiently with a problem, you have to find a proper representation
for the data (e.g. a graph, an array, a string, a hash-table, a binary-tree, etc.) and to
manipulate this representation appropriately (which impacts the choice of the proper representation) to get a representation
of the result.

Numerical calculation is no different. You represent numbers by
sequences of symbols (though some systems use two dimensional
representations). Then you define various manipulation schemes of
these sequences that corresponds to numerical operations you are
interested in.

The invention of the representation 0 for a number measuring the absence of any content, and of positional
numeration system (i.e. representation of numbers) was a major step in
mathematics, and allowed for more effective encoding techniques for
numerical data, and of simpler manipulation techniques for doing the
operations.

This oganization is universal: we always work on representations. The
computer does nothing else, even when doing simple arithmetics.

So the answer to your question is simply, as always: choose a
representation for whatever concepts you want to manipulate an design
the algorithms that manipulate these representations in a way that
corresponds to the abstract manipulations you are interested in.

Typically, if you want to manipulate algebraic expressions containing
constants, variables (identifiers) and operators, you can just
represent them as a rooted tree structures with constants and
variables on the leaves, and the operators on the nodes. That is easy, though more complex representations may sometimes be useful.

Now you may consider your expression as representing a function of a
variable x, that appears among the variables, and you want to
compute the derivative of that expression for x. You can probably imagine
the algorithm yourself, if you know the rules for computing a
derivative, when you do it by hand.  This is a fairly simple recursive
procedure, since the derivative of an expresson can be defined from
the subexpressions and their derivatives, in a way that depends on the
top operator.

You can do things similarly for some trigonometric computations, applying various rules and strategies for transforming trigonometric expressions (such as: $\cos(a+b)=\cos a\cos b-\sin a\sin b$ ), that were used by hand by people (including myself) before computers were available to do it.

Now, many of these manipulation problems are actually hard to
solve. But that comes from the diffculty of mathematics, not from the
fact that it is mechanized in a formal calculation system. There involve a wide variety of techniques and mathematical theories, that have to be adressed individually, and certainly not together in a single question.

As a final remark, we should remember that much of the theory of
computation originates with the search for answers to the
Entscheidungsproblem, a challenge posed by David Hilbert in 1928
about mechanisation of mathematics, and addressed by such people as
Gödel, Church, Turing, and several other pioneers of the field. The
fact that computing devices are now used to do just that, mechanize
mathematics, was only to be expected. It is always pleasing to see
some consistency between the various branches of computer science.