In the diagram above, when two PCs belonging to same network like 192.168.1.10 /24 and 192.168.1.20 /24 but to diffrent Vlans, I suppose they cant't communicate each other.
That is correct.
I wonder how both PCs know which VLAN the other PC belongs to?
They don't. Normal hosts have no knowledge of VLANs.
The switch in between does know as it's configured that way (for layer 2), as is the router (for layer 3). Switches only forward L2 traffic within a VLAN, never across. The whole point of VLANs is to separate hosts from each other.
When PC1 sends a packet to PC2 it uses the router as gateway. The IP packet is addressed for PC2 but the encapsulating frame is addressed for the gateway. The frame travels to the switch untagged, gets tagged for VLAN10 and is forwarded to the router.
The router extracts the packet, decides that it needs to be forwarded out of the subinterface connected to VLAN20, encapsulates it in a frame addressed to PC2, tags it, and sends it towards the switch. The switch decides which port is goes to (based on PC2's MAC address), removes the tag and forwards it to PC2.
When frames arrive at the trunk port between the switch and the router, VLAN tagg is inserted into frames, so that the switch and the router can tell which VLAN the frame belongs to.
A tag is used while the frame is on a trunk. That tag tells the switch (or the router) which VLAN the frame belongs to. The switch only forwards within that VLAN, the router knows which subinterface has been addressed.
The router uses its routing table to decide which subinterface it uses towards the destination IP. Each subinterface is connected to one of the VLANs and the transport frame is tagged for that VLAN.
In the opposite direction, the switch tags each frame according to the ingress port's untagged (native) VLAN.