If two masses are connected by a string that passes over a massless, frictionless pulley as shown in the two examples below, is it necessary that they must have the same velocity and acceleration? If not, wouldn’t the string break since it is inextensible?
Yes, in these types of problems, you assume that the two masses move with the same velocity and acceleration since the string is considered inextensible.
In the two diagrams you have provided, the masses are connected to the string at fixed points - in these cases the ends, but they could be connected to fixed point along the string. The string is usually defined to be inextensible so the distance between any two fixed points on it is constant. It follows from this that the magnitude (but not the direction) of the speed and acceleration of those points along the string must be the same at all times.
There is an assumption here : that the string moves along a fixed path on each side of the pulley. Every point on it follows the same path as the string moves. Even if the string twists in different directions between several pulleys, its path is effectively one-dimensional (1D). If we unwound the string and laid it in a straight line this would not change the speed which each point on it has in 3D space.
As a counter-example, if the hanging masses swing like pendulums as they move up and down, then their speeds and accelerations will be different, even though they remain a fixed distance apart when measured along the string. Their speed and acceleration along the string would be equal, but their speed and acceleration perpendicular to the string would not necessarily be equal.
The assumption also means that the string must remain taut. It does not become slack. We are also assuming that the string does not break.
In another example you give (monkey on a rope) the monkey can climb up or down along the rope. It is not attached at a fixed point. So the distance measured along the rope between the monkey and the hanging weight can change. It follows that in this situation their speeds and accelerations can be different.
If the monkey and hanging block have the same weight, and the monkey is not moving along the rope, then the monkey must exert a force equal to its own weight $W$ on the rope, and the rope must exert the same force on the monkey to keep it from falling.
If the monkey starts climbing up it must exert a force greater than $W$ on the rope. If the monkey climbs or slides down it will exert a force less than $W$ on the rope.