How to know exact right time to duplicate the keycard?
Solution 1:
Others explained how this trick works; but you also asked why it works.
The reason it works is that most of the client computations are done client-side in Payday 2 (this, along with the ridiculous ease of modding the engine, are also the reason hacks are so prevalent in this game).
So, when one person picks up the card, their computer tells the server "Hey, I picked up this card". The server then lets all the other clients know that the card has been picked up. However, if another client picks up the card before they receive that message, then both clients will be holding the same card.
It would be entirely possible to detect this situation and take the card away from one of the clients; but the developers just haven't done that.
Source: Countless hours wading through the Payday 2 Lua code.
Solution 2:
It is possible to dupe the keycard if you get every player to pick up the keycard at the same time on the in-game timer. That way it will appear in every player's inventory. If someone tells you "1:20" you need to watch the timer, and as it turns 1:20 you pick up the keycard. It's kind of an exploit but won't get you banned or anything.
This also works with some other items like thermal paste.
Solution 3:
Duping occurs when two or more players all try to pick up an item at the same time. The window of opportunity is small, but its possible to perform the trick quite consistently with practice.
This can be done by synchronising with the in game timer, or verbally. When I do this with the group I play with (on voicechat), we have the host start at "3..2..1..go" countdown. When you hear the host say go, you pick up the card. The host will delay pressing his button for a fraction of a second to account for lag in the voice chat.
The reverse can also happen, it is possible for two (or more) players to use a keycard each on the same door, effectively losing one of the cards.