In women, the most common cause of pain with penetration is provoked vestibulodynia (PVD), which literally means 'pain at the entrance to the vagina when it is touched'. It is very common to have both PVD and vaginismus (the pelvic floor muscles over tighten, even though you don't want this to happen). Psychosexual therapy works well alongside other treatments such as physiotherapy with a pelvic floor rehabilitation specialist and a clinician prescribing medication.
In men, the most common cause of pain with penetration is Peyronie's disease, curveture of the erect penis. Again, psychosexual therapy can be helpful alongside treatment from a clinician.