Question: Find a necessary and sufficient condition on the set $A \subset \mathbb{R}$ such that $\forall B \subset A, f(B)$ is bounded, where $f$ is any continuous function $f:A \rightarrow \mathbb{R}$.
My attempt: I think the answer should be $A$ must be closed in $\mathbb{R}$. Suppose A is not closed, then we want to show that there exist a function $f:A \rightarrow \mathbb{R}$ and a subset $B$ such that $f(B)$ is unbounded. Since $A$ is not closed, there exist $a_1, a_2, ... , a_n \in A$ such that $a_n \rightarrow a$ and $a \notin A$. Consider the function $f(x)=\frac{1}{x-a}$ which is continuous on $A$. We can find an $\epsilon > 0$ such that $B_a(\epsilon) \cap A$ is a subset of $A$. Then $f(B_a(\epsilon) \cap A)$ is clearly unbounded. However, I don't know how to prove the other direction ($A$ is closed $\implies \forall B \subset A, f(B)$ is bounded). Any help would be greatly appreciated.
Your argument that this fails for non closed $A$ is correct, but your conjecture that 'closed' is a sufficient condition is wrong. Take $A= [a, \infty]$ and as $f= id_R$ the identity. Now take $B=A$. I think the correct answer is that the necessary and sufficient condition you are looking for are compact sets. In $\mathbb{R}$ these are exactly the closed & bounded sets and compact sets have nice feature that the images of comact sets by continuous maps are also compact, therefore also closed & bounded. What does it say about images of all $B \subset A$?