Protoneutron stars as cosmic factories for massive axionlike particles