Coordinate Frames and Rotations
A robot describes what it sees in its own frame. To put that point on a map, you rotate it by the robot heading and then shift it by the robot position.
The transform
$$\mathbf{p}_{\text{world}} = R(\theta)\,\mathbf{p}_{\text{robot}} + \mathbf{t} \qquad R(\theta) = \begin{bmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{bmatrix} \qquad \mathbf{t} = \begin{bmatrix} x \\ y \end{bmatrix}$$
What to notice
The point's coordinates in the robot frame never change as the robot moves. Only its world coordinates change. Rotate the robot and watch the point swing around the robot's origin, not the world origin.
This is exactly what ROS 2 TF2 does for you every time it converts a LiDAR point from base_link to map. In 3D the idea is the same, with a 3 by 3 rotation matrix or a quaternion.