When you need to remove a piece of trim for any reason, carefully pry it away from the wall. Usually, the finishing nails will pull out with the trim.
If you pound the nails out of the trim from the back side, expecting to pull them out with a hammer, you risk damaging the wood by splintering it or chipping the paint.
Instead, use a pair of pincers or Channellocks® to pull the finishing nail through the back side of the trim. This will leave the finished surface intact so that you can reuse it with minimal damage