There are varieties of semigroups like that. Take any finite inherently non-finitely based semigroup $S$, say, the 6-element Brandt monoid $B_2^1$, and the variety $M$ given by all identities of $S$ depending on at most 2 variables. Then all 2-generator semigroups in $M$ are in $var S$, so are finite, but three-generated semigroups in $M$ will be infinite. Warning: the latter is not quite in the literature, it is only proved that some finitely generated semigroup in $M$ is infinite, it may have a bigger rank (in my paper from 1987, Problems of Burnside type and the finite basis property in varieties of semigroups. (Russian) Izv. Akad. Nauk SSSR Ser. Mat. 51 (1987), no. 2, 319--340, 447; translation in Math. USSR-Izv. 30 (1988), no. 2, 295–314, it is $2^2=4$, I think). If you really want rank 3, you should take a slightly bigger monoid than $B_2^1$ or modify my construction.
For groups the answer is unknown. The variety, if exists, is necessarily of finite exponent, hence a solution on the bounded Burnside problem is required. Zelmanov proved that for every prime $p$ there exists a number $k$ such that if all groups of exponent $p$ with $k=k(p)$ generators are finite, then all finitely generated groups of exponent $p$ are finite. For non-prime exponent even that if unknown. Zelmanov's function $k(p)$ grows exponentially.
There are varieties of semigroups like that. Take any finite inherently non-finitely based semigroup $S$, say, the 6-element Brandt monoid $B_2^1$, and the variety $M$ given by all identities of $S$ depending on at most 2 variables. Then all 2-generator semigroups in $M$ are in $var S$, so are finite, but three-generated semigroups in $M$ will be infinite. Warning: the latter is not quite in the literature, it is only proved that some finitely generated semigroup in $M$ is infinite, it may have a bigger rank (in my paper from 1987, it is $2^2=4$, I think). If you really want rank 3, you should take a slightly bigger monoid than $B_2^1$ or modify my construction.
For groups the answer is unknown. The variety, if exists, is necessarily of finite exponent, hence a solution on the bounded Burnside problem is required. Zelmanov proved that for every prime $p$ there exists a number $k$ such that if all groups of exponent $p$ with $k=k(p)$ generators are finite, then all finitely generated groups of exponent $p$ are finite. For non-prime exponent even that if unknown. Zelmanov's function $k(p)$ grows exponentially.