How does CDI work when flying to VOR without DME? Let's show what I mean on an example.

Flying towards a VOR (not knowing the distance), HSI course pointer pointing
   towards the VOR. Let's say the plane is really far from the VOR and we turn
   the course pointer 5 degrees (no matter what way) CDI will move to one side
   (far because of the distance). If the plane was close to the VOR and we turned
   the course pointer 5 degrees CDI would not move as much (or should not because the 
   deviation is really small).

based on this example CDI needs to know distance from VOR to work properly, yet it works without knowing the distance. How?

(If I'm wrong about something, quickly correct me)
The VOR and ILS CDI indicates difference, in degrees, between the radial selected and the radial sensed.

If the plane was far from the VOR and we turn the course pointer 5 degrees, the CDI will move to one side. If the plane was close to the VOR and we turned the course pointer 5 degrees, the CDI would move exactly as much, because it indicates the angular difference in degrees.

This is in contrast to a CDI slaved to GPS, which indeed indicates lateral distance from the selected track in miles (en-route; GPS approach has to simulate ILS).

VOR does nothing with DME. DME is completely independent piece of equipment that was introduced later than VOR. The only relation is that there is a standard correspondence between VOR and DME channels and the DME receiver automatically tunes to the DME frequency corresponding to the VOR or ILS frequency tuned on your VOR/ILS receiver.