std::unordered_map guarantees O(1) time search, but how does it manage collision?
It uses open addressing / separate chaining, see here.
Cppreference claims
Unordered map is an associative container that contains key-value pairs with unique keys. Search, insertion, and removal of elements have average constant-time complexity.
Assuming a situation where all the Hash codes are same, how is the collision handled internally?
The colliding elements are added into another container holding all values that hashed to that bucket. That container is usually a linked list, but there's nothing stopping an implementation using e.g. a binary tree.
My assumption would be totally wrong if the hash code is unique to every key. In that case how is the unique hash code created where there are no collisions at all?
unordered_map isn't required or expected to do anything special to avoid collisions. (Hash codes being "unique to every key" doesn't suffice anyway, as collisions can be created when hash codes are masked or mod-ed into the number of buckets.)
What approach does std::unordered_map's hash function take to guarantee O(1) search?
This is the crux of your misunderstanding. unordered_map has O(1) performance when the hash function does an adequate job of hashing the keys across the buckets. It may degrade to O(n) if the hash function is poor, or has been deliberately targeted by a malicious input of keys known to hash to the same bucket. The Standard does not require implementations to prevent that, but users can supply a cryptographic hash, pick a hash function from a family at runtime, or otherwise make it impractical for a malicious user - or similar inputs generally - to create many more collisions.