I picked an apple from the ground, it was wet with dew and a woodlouse was stuck to it, with its back against the apple. When it got loose, it started flexing its "tail" like this for a while. Why?
It was moistening its respiratory and osmoregulatory organs:
Woodlice as all other terrestrial arthropods face the major challenge of preserving water balance. In their case the two systems that immediately suffer from desiccation are osmoregulation itself and respiration. In woodlice these two functions are carried out mostly by the pleopods: modified leaf-like appendages on the ventral side of the hind body part ("tail") (see here and here some annotated photos and drawings of ventral side of woodlice).
To maintain these structures in moist state woodlice have a number of adaptations, one of them being the ability to "pick up water from external sources via uropodal dipping, with the water moving upwards by capillarity" (see here). Uropods are the tiny rod-like appendages on the tip of the "tail", and dipping of the uropods is exactly what you were observing.