Let $X$ be a (finite) partially ordered set. I am wondering if there is any necessary and sufficient condition for there to exist a proper subset $X' \subsetneq X$ which contains all maximal elements in $X$ and an order-preserving map $f: X \rightarrow X'$ which acts as the identity on maximal elements (of $X$). It's obviously not always true, since if $X$ is the poset with just 1 element, there are no proper non-empty subsets. On the other hand, if $|X| > 1$, the existence of a top or bottom element is clearly sufficient but not necessary. For example, $\{a, b, c, d\}$ with $a < b$ and $c < d$ has no top or bottom element but we can define $f(a) = f(b) = b, f(c) = f(d) = d$ which is a map with the desired properties.
In principle, for a given $X$ it suffices to check whether there exists such a map from $X$ to $X \backslash \{x\}$ for any $x \in X$ but even then it is not clear how to do it. Intuitively, one might guess that the map can always take the form $f(y) = y$ for all $y \neq x$ but this is not true. Consider the poset with maximal elements $A, B, C, D$ and elements $a_i, c_i, d_i$ for $i=1,2$ such that $a_i < A, c_i; c_i < B, C; d_i < D$. Then, if we try to map $X$ to, e.g. $X \backslash \{c_2\}$, and try to impose $f(a_2) = a_2$ and $f(d_2) = d_2$, then we need $a_2, d_2 \leq f(c_2) \leq B, C$ but the only element with these properties is $c_2$. Thus, we are forced to map $a_2, c_2, d_2$ to $a_1, c_1, d_1$. The same happens if you consider $X \backslash \{a_2\}$ and everything else follows from symmetry.
At a higher level of abstraction the question could also be phrased like this:
Denote the set of maximal elements of $X$ as $\text{max}(X)$ and define $\tilde{X} = X \backslash \text{max}(X)$. Define the preorder over the powerset $P(\tilde{X})$ in the following way: $A \geq B$ if there exists an order-preserving map $f: A \cup \text{max}(X) \rightarrow B \cup \text{max}(X)$ such that $f$ acts as the identity on $\text{max}(X)$. As any subset of $X$ can be order-embedded into $X$, $\tilde{X}$ is a bottom element of this preorder. When is $\tilde{X}$ the unique bottom element?
This feels like it might be helpful somehow, either via some category theoretic trick or some relationship between preorders over the powerset of the partial order and the partial order itself, but I'm honestly not sure how.


Edit - as Izaak notes in the comment, while I was thinking about the problem, I lost sight of the fact that $X'$ can contain more points than the maximal elements. So consider this a solution for only the case where $X'$ consists of just the maximal elements.
$X'$ is the set of all maximal elements of $X$. The elements of $X'$ are not comparable to each other, as otherwise the lower one would not be maximal. If $x \le y$, but $f(x) \ne f(y)$, then it would not be true that $f(x) \le f(y)$, since they are distinct elements of $X'$, and thus not comparable. So it must be that $f(x) = f(y)$ if and only if $x$ and $y$ are comparable.
Further, if $x \in X$ and $x \le y' \in X'$, because $x$ is comparable to $y'$, it must be that $f(x) = f(y') = y'$. Thus $x$ can only be under one maximal element.
Thus for each $x',y' \in X', x' \ne y'$ implies that no element of $f^{-1}(x')$ is comparable to any element of $f^{-1}(y')$. But inside $f^{-1}(x')$ every element is comparable to every other element.
Thus such a function $f$ is only possible if $X$ is the disjoint union of a collection of totally ordered sets, each of which has a unique maximal element. with the ordering on $X$ also being the union of the orderings on the subsets.
Note that this applies regardless of whether $X$ is finite or infinite, depending only on the existence of $f$.