The origin of the outstanding mechanical properties of high-entropy alloys (HEAs) is still elusive. In this paper, we have investigated the influence of grain size and temperature on the mechanical properties of polycrystalline CoCrFeNi HEAs via molecular dynamics simulations. The critical grain size for the inverse Hall-Petch effect in CoCrFeNi HEAs is approximately 11.65 nm. During the stage of the positive Hall-Petch effect (where smaller grain sizes lead to higher tensile strength), there is a positive correlation between the tensile strength and dislocation density in CoCrFeNi HEAs. The higher tensile strength at low temperatures in CoCrFeNi HEAs is also attributed to an increase in dislocation density. At low temperatures, the reduced thermal vibrations of atoms slow down the motion of dislocations, leading to an increased storage time of dislocations within the crystal. In the stage of the inverse Hall-Petch effect, due to a significant reduction in grain size, the storage capacity of dislocations within grains decreases. This leads to the accumulation of more dislocations at grain boundaries, forming defects, and consequently causing a decrease in the tensile strength of CoCrFeNi HEAs as the grain size decreases. Our results might be helpful in material design of polycrystal HEAs.