Can a case be a precedent if it hasn’t been published?
Yes, but it is rare.
The doctrine of precedent depends entirely on the court being made aware of the earlier decision by which it is bound. That in turn depends on the earlier case having been in some way published or otherwise publicised. Before the advent of printed law reports, it was not unusual for cases to be noted manually by practitioners and judges, and for the most significant to be recalled anecdotally. But in the modern era, it is rare for a case to be cited in court as a precedent without reference to a published copy of the original judgment, whether in the form of a law report, a digest or case summary, or at the very least a copy of the unreported judgment. In each instance, the document cited will have a recognisable publication reference. (In some cases, where the judgment comes from a collection kept by the court, this will consist of little more than the court’s own reference number.)
However, it is still possible for an unreported judgment to be cited, where the court permits it (usually on the ground that there is no other case on the point: see Practice Direction (Citation of Authorities)  1 WLR 780, para 10). In such a case, there should either be a copy of the unreported judgment produced to the court, or a reliable note of it vouched for by a barrister or solicitor. A discussion or detailed footnote in a textbook might be sufficient, if its accuracy were similarly vouched for. A reference to the case in another, reported case, if sufficiently detailed, might be good enough. However, it seems unlikely that mere anecdotal recollection of the sort that was commonplace before the 16th century would suffice.
In the recent case of Tonicstar Insurance Ltd v Allianz Insurance plc  EWHC 2753 (Comm), Teare J at first instance relied on an unreported case, referred to only as Company X v Company Y (unreported) 17 Jul 2000, in which Morison J had held that a Queen’s Counsel who had more than ten years’ experience of acting in insurance and reinsurance disputes did not qualify for appointment under a particular standard clause in an arbitration agreement. It was the very same point that had come up in the Tonicstar case. It appears that the claimant’s solicitor had a copy of Morison J’s judgment in the earlier case. However, even after being followed in the Tonicstar case, Morison’s judgment remains unreported, even as a note or appendix (which would have been helpful). As it happened, a few month’s later the Court of Appeal reversed Teare J’s decision in Tonicstar  EWCA Civ 434;  Bus LR 2347, overruling Company X v Company Y and thereby rendering it no longer worth citing on the point.
The existence of internet case law databases and the attribution of neutral citations has made it much less likely that a recent judgment would be cited without being published in some form, even if unreported; but the Tonicstar cases demonstrates that it is still possible.