Encrypting wallet manually instead of using hardware wallet i am new to this community and like to know why one should prefer a hardware wallet instead of using encryption algorithm like AES-256 along with PKDF2 to secure crypto wallets ?
i currently hold btc in trezor wallet and planning to use AES to manually encrypt private keys by myself. 
I have been playing around with the crypto wallet encryptor,

https://github.com/sufiyanghori1/crypto-wallet-encryptor

which seems to be pretty effective.
it takes private key and a custom password as an input and encrypt it using AES-256.

i have read on various forums people using it but not sure if its any better than actual hardware wallet ?
The benefit of hardware deterministic wallets is that your keys are permanently kept offline and secret, as long as you don't leak your seed words. To spend bitcoin, the transaction signing is performed on the device, keeping your keys safe.

If you encrypt the keys yourself (I'm assuming you're talking about bitcoin private keys, not an HD wallet seed), it depends how you store them. I can see three risks:


If you're planning on storing them online and encrypt them all with the same passphrase, then you're reducing the security of your keys to the single passphrase. If you leak your passphrase, anybody with access to your data can decrypt and use your keys. If you don't store them online (including on a system with access to the internet) however, this is less of a risk.
Signing transactions. In order to sign transactions, you're going to have to decrypt your key and run it through some software. If you do this online, it's very risky. If you do it offline, you're still at risk of keyloggers and other malicious software that could be present on your machine. This also applies to when you generate your keys in the first instance.
Loss. If you lose your encrypted data or your passphrase, your bitcoin is lost. With an HD wallet, if you lose the wallet you can recover with the seed words. If you lose the seed words you can still use the wallet to transfer to an alternative address.


If you do decide to use the passphrase method, note that there is already a standard for protecting a private key with a passphrase (example implementation - check the paper wallet section), so it's not necessary to encrypt it separately yourself.