What happens if a magnetar collapses into a black hole? Assume there is a neutron star with a magnetic field and no net electrical
charge. What happens to the magnetic field if it gains some mass and
collapses into a black hole?
 A: Magnetars are neutron stars where the extremely strong magnetic field originates from something called the magnetohydrodynamic process in the turbulent extremely dense superconducting fluid, that persist even after the neutron star settles into equilibrium.

These fields then persist due to persistent currents in a proton-superconductor phase of matter that exists at an intermediate depth within the neutron star (where neutrons predominate by mass).

https://en.wikipedia.org/wiki/Magnetar
You are asking what would happen after the magnetar would collapse into a Black Hole  (actually it needs to gain stress-energy, not mass). I will assume you are asking about a Kerr Black Hole, that is, one that has no magnetic field officially.
Now after the collapse, the new Black Hole would have no magnetic field, that is, outside the Event Horizon, we could not observe any magnetic field. The characteristics of the Black Hole would still be describable by the Kerr metric.
It is very important that the answer to this question depends upon the source of the magnetar's magnetic field. Since that is based on the structure (and internal magnetohydrodynamic processes) of the magnetar, that would be destroyed as the extreme levels of gravity would win over the magnetar's internal structure to the lowest level, the magnetar's inside magnetohydrodynamic structure would eventually be torn into its elementary constituents.
So the answer to your question is that after the collapse, there would be no magnetic field observable outside the Event Horizon.
Just a note, officially, we do not have a clear declaration as of today whether Black Holes themselves could have magnetic fields, though, we have detected magnetic fields around Sagittarius A, near the event horizon, the source of these might just be the accretion disk and not the Black Hole itself.
https://en.wikipedia.org/wiki/Black_hole#cite_note-152
So officially, Kerr type Black Holes do not have a magnetic field, and the fact that the original (before the collapse) astrophysical object is a magnetar does not change this.
A: This paper by Lyutikov and McKinney describes this precise scenario.   I'll provide a brief summary of their results here.

One of the crucial underlying assumptions made when deriving the no-hair theorem is that the region outside the event horizon is a vacuum.  However, a rapidly spinning, magnetized neutron star can induce vacuum breakdown, leading to the existence of self-generated currents in the magnetosphere.  That is, an initial spinning dipole field with no external currents evolves into a magnetized black hole supported by currents outside the event horizon.  In particular, rotation-induced poloidal currents cause magnetic field lines which originate near the poles of magnetar to "open up" to infinity.
The presence of a conductive plasma in the magnetosphere freezes magnetic field lines into the surface.  As the magnetar collapses, the closed field lines are absorbed into the event horizon.  However, the open lines, which connect the magnetar surface to infinity, persist and end up connecting the event horizon to infinity.  The resulting field relaxes to a split monopole configuration which looks something like this:

Over time, the equatorial current sheet dissipates and the field lines which are anchored to the event horizon are able to "slide off" and the magnetic field decays.  However, this process relies on the finite resistivity of the plasma in the magnetosphere, and is slow when compared to the timescale one would naively expect from the no-hair theorem.  As a result, magnetized black holes can persist for quite a while even in the absence of externally supplied accretion material.
