Wait at least until the scabs are gone and then add one week. This will guarantee that the grafts and the hair will not catch on the material of the beanie. Make sure that the beanie is washed before using it.
Usually, You can start wearing a loose hat after a day, but a tight hat after a week. If it is a commercial or heavy hat after two weeks. For the first two weeks, You need to make sure the hat is clean and is not touching the grafts directly. If you have concerns you should ask your hair transplant doctor for advise.