A goal is usually set with respect to /base_link. When you give a 2d_nav_goal in rviz, the frame i.d is set to base link base_link (goal.target_pose.header.frame_id = "base_link"
).
We wait for transform is between /map and /base_link. It happens this way, the robot_pose_ekf node publishes the transform between /odom and /base_link and the /amcl node creates the /map frame, establishes a connection with /odom and in turn calculates the transform between /map and /base_link. So, when you set a goal on map frame, (it waits for transform between /map and /base_link), calculates the transform and publishes it on the /base_link frame.
Read more here and here for better understanding.