Subquery with variable in where
The problem with your query performance is that x = 5 or y = 5 queries don't usually use indexes.
We help this out with your code by creating greatest and least values as generated columns with indexes.
alter TABLE `pendency`
add lpen int as (least(id_user_pen,id_user_req_pen)),
add gpen int as (greatest(id_user_pen,id_user_req_pen)),
add index gpen(gpen),
add index lpen(lpen);

Then use a union, first to grap those with 5 as the greater user (talking to 1-4) and then 5 as the least talking to the others.
(
SELECT
    p.id_pen,
    p.id_env_pen,
    0 AS id_star,
    FALSE AS is_star,
    p.text_pen AS text_send,
    p2.text_pen AS text_response,   
    DATE_FORMAT(p.created_at_pen, '%Y-%m-%d %H:%i:%s') AS send_datetime,
    DATE_FORMAT(p2.created_at_pen, '%Y-%m-%d %H:%i:%s') AS response_datetime,
       
    p.time_res_pen,
    p.state_pen,
    p.created_at_pen
FROM pendency AS p
JOIN pendency p2 ON
  p2.id_pen_req_pen = p1.id_pen
  AND p.gpen= 5
)
UNION ALL
(
SELECT
    p.id_pen,
    p.id_env_pen,
    0 AS id_star,
    FALSE AS is_star,
    p.text_pen AS text_send,
    p2.text_pen AS text_response,   
    DATE_FORMAT(p.created_at_pen, '%Y-%m-%d %H:%i:%s') AS send_datetime,
    DATE_FORMAT(p2.created_at_pen, '%Y-%m-%d %H:%i:%s') AS response_datetime,
       
    p.time_res_pen,
    p.state_pen,
    p.created_at_pen
FROM pendency AS p
JOIN pendency p2 ON
  p2.id_pen_req_pen = p1.id_pen
  AND p.lpen= 5
)

Joining to users, handling of (id_user_req_pen!= -10) and ordering has been left as an exercise to the reader you.