There is insufficient information in this question to derive f(x) uniquely, so I have just used a simple example to illustrate the process.
Let f'(x)=ax+b, then f(x)=ax2/2+bx+c where a, b, c are constants.
f'(2)=2a+b=3, f(2)=2a+2b+c=5.
From these two equations, (2a+2b+c)-(2a+b)=5-3=2, so b+c=2 for which there are many solutions for b and c, and hence many solutions for all three constants. So b=2-c, and a=(3-b)/2=(3-2+c)/2=(c+1)/2.
For example, if c=1, then a=b=c=1; f(x)=x2/2+x+1, f'(x)=x+1; f(2)=5, f'(2)=3.
If c=3, then b=-1, a=2, f(x)=x2-x+3, f(2)=5; f'(x)=2x-1, f'(2)=3.
If c=0, then b=2, a=½, f(x)=x2/4+2x, f(2)=5; f'(x)=x/2+2, f'(2)=3.
If g(x)=(f(x))2, then for each of these examples we have g(x)=(x2/2+x+1)2, (x2-x+3)2, or (x2/4+2x)2.