How can the wallet identify public addresses are linked to a private address As the wallet can generate many public addresses from a private address. How does the wallet know that any transaction from or to the wallet is for that private wallet if the in and out can be any number of public addresses.
While exact implementations between wallets might differ, the general approach is usually similar to the following:


A wallet generates a private key (or a set of keys) based on an HD wallet, or just individual random keys
The public keys for private keys generated in 1. are calculated, and used to create the desired address scripts (p2pkh, p2sh (wrapped segwit/multisig), p2wpkh, p2wsh).
The wallet stores the private key, along with a mapping to which address script uses that key.
The wallet constantly scans the mempool and new blocks for outputs that send Bitcoin to the address scripts calculated in 2. When it discovers such an output, it adds the coins to the wallet balance and informs the user.


There are implementation specific variations on this (for example, an HD wallet may not store individual private keys, and store a mapping of the derivation path from the root key and the address script instead).

For an actual example, let's say our wallet has the private key for the address 1F1tAaz5x1HUXrCNLbtMDqcw6o5GNn4xqX. The HASH160 for the public key of this address is 99bc78ba577a95a11f1a344d4d2ae55f2f857b98, and the locking script is 76a91499bc78ba577a95a11f1a344d4d2ae55f2f857b9888ac. This locking script is what appears in the actual bitcoin transaction that sends coins to this address.

The wallet will store the private key, and make a note that the private key corresponds to that locking script. It will then scan the bitcoin blockchain for transactions which have an output that matches that locking script.